aspose file tools*
The moose likes Threads and Synchronization and the fly likes deadlock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "deadlock" Watch "deadlock" New topic
Author

deadlock

abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
Hi!


http://www.java-samples.com/showtutorial.php?tutorialid=307

This is an example of deadlock, But I can't understand where is the deadlock in that code?

The deadlock happened when two thread want to access one resource, But I don't such thing in that coe

Please guide me


[HENRY: Formatted Code]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18988
    
  40

abalfazl hossein wrote:
http://www.java-samples.com/showtutorial.php?tutorialid=307

This is an example of deadlock, But I can't understand where is the deadlock in that code?

The deadlock happened when two thread want to access one resource, But I don't such thing in that coe


I think your definition of deadlock is incorrect. There are actually many ways to deadlock, and the example is defining it as and showing as... A deadlock can occur when two threads are trying to grab two different locks. They each grab one of the locks, and then wait for the other lock. In this case, the deadlock is occuring because neither can grab the other lock because it is owned by the other thread -- and neither will release the lock that they did grab because they are both in a wait state waiting for the other lock. This condition can't be resolved, hence, deadlock.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
OK, As you define the deadlock. Now Please tell me how deadlock happened in that code?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18988
    
  40

abalfazl hossein wrote:OK, As you define the deadlock. Now Please tell me how deadlock happened in that code?


You can't see it? It is pretty clear.... plus the code is loaded with print statements so that you can follow it.

Try it. Run the code.... And if you still don't see it, describe what you do see, and we'll give you some hints on where you went wrong.

Henry
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
There is only one lock fro every object.

Then when Mainthread takes lock of class A,Racing thread couldn't take lock of class A.
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
You can see a full thread and monitor cache dump by pressing CTRL-BREAK on a PC (or CTRL-\\ on Solaris).


http://www.java-samples.com/showtutorial.php?tutorialid=307

I use Netbeans,I press CTRL-BREAK while I run that program , but I didn't see anything.

I search and find about Netbeans:

http://profiler.netbeans.org/

But I didn't see any link to download this add on....

and don't find that on Netbeans....

I also try SendSignal in cmd....But unlucky....I don't know how to find the ID of process that is belongs to program that I run .....

I want to see thread dump. What is the simplest way?
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
The path to a secure application ,IBM

e. Race conditions
Two processes might share control or data. Race conditions is
the term applied to compromising this sharing, which typically
results from synchronization errors, when the potential exists
for process conflicts, and a resulting vulnerability. A typical
exploit interrupts a pair of sequential calls that are meant to be
performed automatically without interruption by another
thread or process on the machine with a third process.

One example is the combined checking of access rights to a
file, followed by a subsequent call to write or read that file. By
interrupting the process between the two calls, an attacker can
rewrite or modify the file because this behavior is expected.
The attacker can place inappropriate information into a file,
or perhaps access an inappropriate file


May someone explain more about the example?
 
 
subject: deadlock