My understanding is that threads in theory are executed in parallel. JVM decides; when a resource is available which thread to pick from the waiting thread queue (based on some
You cannot tell the thread scheduler which order to execute threads in. If you need to ensure that a certain piece of code which is running on thread A must run before another piece of code running on thread B, you must enforce that order using locks or wait()/notify().
For example, you could use a variable which was accessible to both threads as a "flag" to indicate whether it is safe for thread B to go ahead. Thread B could wait() in a loop, checking the value of that variable. Then when it was safe for thread B to run, thread A could set the variable and wake thread B up using notify().
So yes, it is possible to enforce a desired order between things which happen on different threads. Generally, though, you want to avoid writing such low-level, detailed code. It is just too easy to get things wrong and cause subtle, hard-to-find bugs. When you are dealing with multithreaded code, always try to use high-level building blocks if you can.