Parallel process in java


 
Thread Tools Search this Thread
Top Forums Programming Parallel process in java
# 1  
Old 05-13-2012
Parallel process in java

Hello;

Quote:
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
# 2  
Old 05-13-2012
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)
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 05-14-2012
Quote:
Originally Posted by 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.
This User Gave Thanks to jlliagre For This Post:
# 4  
Old 05-17-2012
Thank you so much for help.
Code:
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?

Last edited by Scrutinizer; 05-17-2012 at 07:29 AM.. Reason: code tags instead of quote tags
# 5  
Old 05-17-2012
Code:
...
Thread thread1 = new Thread("New Thread1") {
  public void run(){ 
  while(thread.isAlive())
  {
    ...
  }
...

This User Gave Thanks to jlliagre For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Monitoring processes in parallel and process log file after process exits

I am writing a script to kick off a process to gather logs on multiple nodes in parallel using "&". These processes create individual log files. Which I would like to filter and convert in CSV format after they are complete. I am facing following issues: 1. Monitor all Processes parallelly.... (5 Replies)
Discussion started by: shunya
5 Replies
Login or Register to Ask a Question