I have some code that I want to only allow access to by one thread. I know how to accomplish this using either synchronized blocks or methods, but will this work i
synchronized
You can use a in-memory-data-grid like http://www.hazelcast.com/ for this too. This is a distributed data structure that supports locking.