Created
          December 1, 2016 15:32 
        
      - 
      
- 
        Save computereasy/b53e9f55512bf5a077744ff73e8f93c2 to your computer and use it in GitHub Desktop. 
    Scala thread pool example
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import java.util.concurrent.Executors | |
| val pool = java.util.concurrent.Executors.newFixedThreadPool(2) | |
| 1 to 10 foreach { x => | |
| pool.execute( | |
| new Runnable { | |
| def run { | |
| Thread.sleep(2000) | |
| println("n: %s, thread: %s".format(x, Thread.currentThread.getId)) | |
| } | |
| } | |
| ) | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment