There are many ways to share same Object between multiple threads. You can use a BlockingQueue to pass an Object from one thread to another thread. You can also use Exchanger class for this purpose. An Exchanger is a bidirectional form of a SynchronousQueue in Java.
It can be retrieved via getServletContext() method. ServletContext has an "application" scope, and can also be used to pass information between servlets within the same application, via methods setAttribute("name", object) and getAttribute("name").
To share data between users of the web application we can put a shared object in application scope which can be done by calling setAttribute() method of the ServletContext . By this way data can then be accessing by other users by calling the getAttribute() method of the ServletContext .
I have 2 separate Java Applications running at a time. (Two separate javaw.exe) I need to share an object between them while they are running.
What is the simplest way to achieve this without having any permanent storage?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With