SHARE
TWEET

Untitled

a guest Feb 20th, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class FTPUpload extends Thread {
  2.  
  3.       public static void main (String args[]) {
  4.         _//some code_
  5.         final Thread thread1 = new Thread(){;
  6.           public void run() {
  7.     _//code of thread1_
  8. }  
  9.  
  10. final Thread thread2 = new Thread(){;
  11.   public void run() {
  12.    _//code of thread2_
  13.  
  14. }
  15.  
  16. thread1.start();
  17. thread2.start();
  18.  
  19.        }
  20.     }
  21.    
  22. final Lock lock = new ReentrantLock();
  23. final Condition done = lock.newCondition();
  24. ...
  25. // in thread 1 when finished
  26. lock.lock();
  27. try {
  28.   done.signalAll();
  29. } finally {
  30.   lock.unlock();
  31. }
  32. ...
  33. // in thread 2 for waiting
  34. lock.lock();
  35. try {
  36.   done.await(30,TimeUnit.SECONDS); // wait for the done or give up waiting after 30s
  37. } finally {
  38.   lock.unlock();
  39. }
  40.    
  41. final CountDownLatch latch = new CountDownLatch(1);
  42. ...
  43. // in thread 1
  44. latch.countDown();
  45. ...
  46. // in thread 2
  47. latch.await(30,TimeUnit.SECONDS)
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