Advertisement

07.16.2008 at 02:57PM PDT, ID: 23571463
[x]
Attachment Details

Need help understanding threads in java

Asked by precado999 in Programming Languages, Java Programming Language, New to Java Programming

Tags: Java

I need help understanding threads in Java. What are they? how are they used? Also need help understanding the code in the bottom. What is it doing? what are the possible outcomes? what does this do
synchronized(lock)? If someone can help understand this it would be greatly appreciated.

thanksStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
final Object lock = new Object();
Thread t1 = new Thread() {
public void run() {
System.out.print("a");
synchronized(lock) { lock.wait(); }
System.out.print("b");
}
};
Thread t2 = new Thread() {
public void run() {
System.out.print("c");
synchronized(lock) { lock.notify(); }
}
};
t1.start();
t2.start();
[+][-]07.16.2008 at 03:05PM PDT, ID: 22020640

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Programming Languages, Java Programming Language, New to Java Programming
Tags: Java
Sign Up Now!
Solution Provided By: CEHJ
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.16.2008 at 04:47PM PDT, ID: 22021216

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.16.2008 at 10:19PM PDT, ID: 22022506

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628