aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes threads Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "threads" Watch "threads" New topic
Author

threads

Venkat Ramsimha
Ranch Hand

Joined: Dec 28, 2004
Posts: 127
Hi all some queries on threads

1.IF IS IT TRUE TO SAY THAT MORE THAN ONE THREAD HAS THE SAME NAMES THAN IN THAT CASE HOW TO IDENTIFY THE THREADS WITH SIMILAR NAMES?

2.public class TwoThreadsDemo1
{
public static void main (String[] args)
{
new Thread("Jamaica").start();
new Thread("Fiji").start();
}
}
IN THE ABOVE PROGRAM WHICH THREAD WILL START ITS EXECUTION?HOW THE PROCESS GOES ON?


3.WHTS THE PRORITY SET WHEN A THREAD IS BEING CREATED AND WHTS THE DEFAULT
PRIORITY?

4.objects having locks and wait sets are referred to as monitors?what actually are the monitors


Tnanks
venkatramsimha
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Hi,

well if you set the same name for 2 threads, the method getName() will return the same String.
Maybe you can define your own status inside the thread, use something else than the name to identify them...

The start() method starts a new thread and execute the run() method.
Since you do not override the run() method in your thread declaration, the default Thread.run() is executed and does nothing.


try this instead...


By default, threads are set to priority 5, out of 10, which is "normal".
static constant are accessible in Thread




Also, you can use the static method Thread.currentThread() to get a reference to the current thread object.
This can be usefull to verify in which thread you are currently...



Below some details on the monitors, found on the web

Thread Synchronization
Problems may occur when two threads are trying to access/modify the same object. To prevent such problems, Java uses monitors and the synchronized keyword to control access to an object by a thread.
Monitor

Monitor is any class with synchronized code in it.
Monitor controls its client threads using, wait() and notify() ( or notifyAll() ) methods.
wait() and notify() methods must be called in synchronized code.
Monitor asks client threads to wait if it is unavailable.
Normally a call to wait() is placed in while loop. The condition of while loop generally tests the availability of monitor. After waiting, thread resumes execution from the point it left.

you might want to read this page Thread details - Related SCJP Objective

Regards,
Alex
[ April 29, 2005: Message edited by: Alex Turcot ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: threads
 
Similar Threads
problem with monitors :
doubt regarding Threads?
Thread problem please help
A question for beginners
[B]Class Monitor Vs. Object Monitor[/B]