Advertisement
Guest User

Untitled

a guest
Feb 1st, 2015
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1.     public static void atLeastOne(int n, Runnable r){
  2.         Thread[] t = new Thread[n];
  3.         for(int i=0;i<n;i++)
  4.             t[i] = new Thread(){
  5.                 public void run(){
  6.                     r.run();
  7.                     if(!isInterrupted()){
  8.                         for(Thread x : t)
  9.                             if(x != currentThread())
  10.                                 x.interrupt();
  11.                     }
  12.                 }
  13.             };
  14.        
  15.         for(Thread x : t)
  16.             x.start();
  17.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement