A tough Java question on threads

After reading my core Java interview questions, my friend and a colleague Mike Polyak said that I should include the following advanced interview question on Java threads synchronization:

In the class below, is method getIt() thread safe and why?

public class X {

private long myVar;

public void setIt(long var){

myVar = var;


public long getIt() {

return myVar;



If you have an idea what “s the right answer is, feel free to write it in the Comments section of this blog. I “ll publish the answer in a week in this very blog, so stay tuned hellip;

Happy Independence Day for those who celebrates it!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s