SHARE
TWEET

Untitled

a guest Mar 25th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. package programparalel;
  3.  
  4. /**
  5.  *
  6.  * @author Luiz Zimmermann
  7.  */
  8. public class ProgramParalel extends Thread{
  9.  
  10.    
  11.    static int saldo = 0;
  12.    
  13.     @Override
  14.     public void run(){
  15.          for(int i = 0;i<999;i++){
  16.              this.saldo++;
  17.          }
  18.     }
  19.    
  20.     public static void main(String[] args) {
  21.        
  22.  
  23.         //Cria as Threads
  24.         ProgramParalel t1 = new ProgramParalel();
  25.         ProgramParalel t2 = new ProgramParalel();
  26.         ProgramParalel t3 = new ProgramParalel();
  27.         ProgramParalel t4 = new ProgramParalel();
  28.         ProgramParalel t5 = new ProgramParalel();
  29.        
  30.         //Executa as threads
  31.         t1.start();
  32.         t2.start();
  33.         t3.start();
  34.         t4.start();
  35.         t5.start();
  36.        
  37.  
  38.         try{
  39.            t1.join();
  40.            t2.join();
  41.            t3.join();
  42.            t4.join();
  43.            t5.join();
  44.        
  45.         }catch(Exception e){
  46.             e.printStackTrace();
  47.         }
  48.        
  49.         System.out.print(saldo);
  50.     }
  51.    
  52.    
  53.    
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top