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 how to find the variable get updated by simultaneous threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "how to find the variable get updated by simultaneous threads" Watch "how to find the variable get updated by simultaneous threads" New topic
Author

how to find the variable get updated by simultaneous threads

Krishnaa Kumar
Greenhorn

Joined: May 05, 2011
Posts: 25
Hi,

I have variable that gets updated by different threads simultaneously. I don't want to control the simultaneous update through synchronization. Instead, i need to know how many threads updated the variable value simultaneously. I should not use synchronization concept as it will increase the serving time of those threads by waiting to get object lock released. How can i achieve this in Java.

-Krishna
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Use a static counter and allow the variable update in a public method. Whenever an update is done, you can increment the counter.
Krishnaa Kumar
Greenhorn

Joined: May 05, 2011
Posts: 25
I have many concurrent running http request serving threads. They will be creating an Object(? extends Object) for every request and save the object in a list.
Advice me some good data structure to implement this list.
I can't use ArrayList since it was not thread safe.
I dont like to use Vector - since its synchronized, it will make other threads to wait when one of the http thread was saving the object.
Also tried LinkedList, but there is data loss due to concurrent update.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
I should not use synchronization concept

This does not make sense. Whenever you use shared mutable state, you must synchronize access to it, or the results will be unpredictable. Obviously, you should not synchronize the entire code, but just those parts that access the shared mutable state. If this is just an integer counter you can use an AtomicInteger for the task.

You should work through this entire section of the Java Tutorial: http://docs.oracle.com/javase/tutorial/essential/concurrency/index.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to find the variable get updated by simultaneous threads
 
Similar Threads
Problem with threads (concurrency)
Static variable
Race Condition for Threads to increment a variable
Synchronization and Performance
Single object versus multiple