Parallel process in java

Hello;

Please Are both threads execute in parallel?
Thank you

The answer depends upon the configuration of the hardware. With multi-core cpus or multiple cpus on a single system (or virtual system/zone) the asnswer is: yes it can run in parallel.

example code:
The SimpleThreads Example (The Java� Tutorials > Essential Classes > Concurrency)

1 Like

Yes, unless the first launched complete too fast, the second one will run in parallel with the first one. They will run simultaneously (jim mcnamara point) only if more than one core/cpu is available to your JVM, otherwise, they will use distinct slices of CPU time.

1 Like

Thank you so much for help.

Thread thread = new Thread("New Thread") {
public void run(){ 
//instruction
}
}; 
Thread thread1 = new Thread("New Thread1") {
public void run(){ 
while(condition)
{
//instruction1

}
}
}; 
thread.start();
thread1.start();

Please, How to leave the while when thread finish its execution?

...
Thread thread1 = new Thread("New Thread1") {
  public void run(){ 
  while(thread.isAlive())
  {
    ...
  }
...
1 Like