Win a copy of Rust Web Development this week in the Other Languages forum!

Nomaan Butt

Ranch Hand
+ Follow
since Oct 19, 2011
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Nomaan Butt

Below text from the link mentioned by you above specifies that issues with lazy initialization of singletion have been taken care off.

JDK5 and later extends the semantics for volatile so that the system will not allow a write of a volatile to be reordered with respect to any previous read or write, and a read of a volatile cannot be reordered with respect to any following read or write

10 years ago
call the sleep() method just after you call the start() method of Thread A, this will validate Keith's reply

Since Test class is being added dynamically to ByValue class and Test is a static field in the ByValue, is it possible that when one Thread RESET this static Test field the other thread sees a NULL value?

dynamic initiation has nothing to do with your query.

Sandra Wilson wrote:Hi, so what has fixed it finally? Am looking for a solution to the same scenario. Posting the solution here would be of great help.

as Jeff has said this site is NotACodeMill so i will not give the complete code, this is just to help you(Sandra)
Below class 'Data' is based on singleton pattern and write to file is synchronised in writeToFile() method on the instance of Data class, here there is no need to synchronize on the PrintWriter Object
Now the runnable code for the multiple threads execution,

Now create multiple threads through Pool or directly and check the execution.
as winston suggested, make a Person class like below

and create a list of type Person and add objects to it like this

you can change the compareTo() method according to your need
hope this may help you.
10 years ago

Jeff Verdegan wrote:
Actually, the Future is tied to your tasks, not to the threads that execute them. And I would argue that for this reason, it's probably a more appropriate approach than the other one suggested earlier.

@OP: If you're using a thread pool in the first place, it means you have deliberately chosen to separate your tasks from the threads that execute them, and it seems more likely that you would care about when those tasks are done, rather than caring about the threads. If you really do want to know when the threads are all done, it seems simpler to just manage the threads yourself, and call their join() methods.

quite right Jeff

samir ware wrote:Hello Ranchers
Though is there any way by which I will get to know that now all the threads are done with the working and all of them came back in to the thread pool . I need to catch this event as I want to perform some operation when threads gets done with their processing .

you can achive this using the isDone() method of Future interface, put all the tasks(Callable) in an ArrayList and pass them to the below method

then call the isDone() method on the retuned list of Futures to find if they have finished.
isDone() will return true if the task has finished.

Future interface is used to find the states of the current threads in pool.
put the data in a java properties files for example like
here data is separated by '|'
then read the file as an input stream using
then retrieve the data using

split the data retrevied from the file using split method like this

then initiate the Personal class objects and put them in ArrayList

Hope this will help
10 years ago
use the normal for loop then
you can't modify a string object but you can change the string reference as Tomasz pointed out you have changed the reference of 's'.
create another scheduled executor service for checking the queue size at regular intervals

quite right,
we can say instance variables of the super class get hidden in the subclass. we can access them through the super class which is happing in the above code and also your precedence explanation is right i believe.

This will create the singleton object if it doesn't exist.