# Parallel process in java

**URL:** <https://community.unix.com/t/parallel-process-in-java/310115>\
**Category:** Programming\
**Created:** [May 13, 2012, 7:29am UTC](https://community.unix.com/t/parallel-process-in-java/310115 "2012-05-13T07:29:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chercheur857](https://community.unix.com/letter_avatar/chercheur857/32/5_5575768a8748004e209b776fc1b2916d.png) [@chercheur857](https://community.unix.com/u/chercheur857)\
**Post date:** [May 13, 2012, 7:29am UTC](https://community.unix.com/t/parallel-process-in-java/310115/1 "2012-05-13T07:29:15Z")

</div>

Hello;

> [@](#):
>
> Thread thread = new Thread("New Thread") {  
> public void run(){   
> //instruction  
> }  
> };  
> Thread thread1 = new Thread("New Thread1") {  
> public void run(){   
> //instruction1  
> }  
> };  
> thread.start();  
> thread1.start();

Please Are both threads execute in parallel?  
Thank you

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/5_5575768a8748004e209b776fc1b2916d.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [May 13, 2012, 9:19pm UTC](https://community.unix.com/t/parallel-process-in-java/310115/2 "2012-05-13T21:19:13Z")

</div>

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)](http://docs.oracle.com/javase/tutorial/essential/concurrency/simple.html)

---

<div class="post-metadata">

**Author:** ![jlliagre](https://community.unix.com/letter_avatar/jlliagre/32/5_5575768a8748004e209b776fc1b2916d.png) [@jlliagre](https://community.unix.com/u/jlliagre)\
**Post date:** [May 14, 2012, 3:15am UTC](https://community.unix.com/t/parallel-process-in-java/310115/3 "2012-05-14T03:15:35Z")

</div>

> [@chercheur857](#):
>
> Please Are both threads execute in parallel?

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.

---

<div class="post-metadata">

**Author:** ![chercheur857](https://community.unix.com/letter_avatar/chercheur857/32/5_5575768a8748004e209b776fc1b2916d.png) [@chercheur857](https://community.unix.com/u/chercheur857)\
**Post date:** [May 17, 2012, 6:13am UTC](https://community.unix.com/t/parallel-process-in-java/310115/4 "2012-05-17T06:13:56Z")

</div>

Thank you so much for help.

```nohighlight
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?

---

<div class="post-metadata">

**Author:** ![jlliagre](https://community.unix.com/letter_avatar/jlliagre/32/5_5575768a8748004e209b776fc1b2916d.png) [@jlliagre](https://community.unix.com/u/jlliagre)\
**Post date:** [May 17, 2012, 4:54pm UTC](https://community.unix.com/t/parallel-process-in-java/310115/5 "2012-05-17T16:54:39Z")

</div>

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

```
