I have two threads that need to use one variable. They run forever and constantly needs the updated value of the variable. Now I am aware of the race condition and am using synchronized. However, the two threads are of different classes and I don't think synchronized is quite effective. The local memory is not reconciled with the main memory. Any idea on how I may go about solving this problem? (It also doesn't work without synchronized either)

Thanks all in advance.

Can u put up the code here please. This would make easier to solve the problem.

> The local memory is not reconciled with the main memory

This might be because of each Thread is having a cached copy of your data; using the volatile keyword might just do the job.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.