Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FTPUpload extends Thread {
- public static void main (String args[]) {
- _//some code_
- final Thread thread1 = new Thread(){;
- public void run() {
- _//code of thread1_
- }
- final Thread thread2 = new Thread(){;
- public void run() {
- _//code of thread2_
- }
- thread1.start();
- thread2.start();
- }
- }
- final Lock lock = new ReentrantLock();
- final Condition done = lock.newCondition();
- ...
- // in thread 1 when finished
- lock.lock();
- try {
- done.signalAll();
- } finally {
- lock.unlock();
- }
- ...
- // in thread 2 for waiting
- lock.lock();
- try {
- done.await(30,TimeUnit.SECONDS); // wait for the done or give up waiting after 30s
- } finally {
- lock.unlock();
- }
- final CountDownLatch latch = new CountDownLatch(1);
- ...
- // in thread 1
- latch.countDown();
- ...
- // in thread 2
- latch.await(30,TimeUnit.SECONDS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement