File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes deadlock Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "deadlock" Watch "deadlock" New topic
Author

deadlock

abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 547
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]

This message was edited 1 time. Last update was at by Henry Wong

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 13412

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: 547
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: 13412

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

This message was edited 2 times. Last update was at by Henry Wong

abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 547
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: 547
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: 547
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?

This message was edited 1 time. Last update was at by abalfazl hossein

 
 
subject: deadlock
 
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture