Use a CountDownLatch with a counter of 1.
CountDownLatch latch = new CountDownLatch(1);
Now in the app thread do-
latch.await();
In the db thread, after you are done, do –
latch.countDown();
More Related Contents:
- I have wondered why ‘new Thread(new Thread(),”string”);’ is running correctly
- What’s the difference between Thread start() and Runnable run()
- Difference between volatile and synchronized in Java
- How many threads can a Java VM support?
- What does java.lang.Thread.interrupt() do?
- Java thread affinity
- How does synchronized work in Java
- How to obtain JNI interface pointer (JNIEnv *) for asynchronous calls
- SwingWorker in Java [closed]
- What does this thread join code mean?
- What are the advantages of using an ExecutorService?
- Should I use a separate ScriptEngine and CompiledScript instances per each thread?
- Is ExecutorService (specifically ThreadPoolExecutor) thread safe?
- Use cases for RxJava schedulers
- Are Thread.stop and friends ever safe in Java?
- ThreadPoolExecutor Block When Queue Is Full?
- Should you synchronize the run method? Why or why not?
- Why does Java not see the updated value from another thread?
- What is adaptive spinning w.r.t lock acquisition?
- Why is Swing threading model considered wrong and how should it be? [closed]
- Testing initialization safety of final fields
- How can I wrap a method so that I can kill its execution if it exceeds a specified timeout?
- Thread safe Hash Map?
- Java multithreading – thread priority
- How to listen for Firebase setValue completion
- Is Cipher thread-safe?
- Write end dead exception using PipedInputStream java
- Why is Thread.stop() so dangerous
- Updating your UI and forcibly waiting before continuing JavaFX
- How to test methods that call System.exit()?