I want to use synchronize method to lock some data only for one user to use at same time, but we use 2 application servers. This means we have 2 jvm, how to solve this problem?
thanks
-
how to use synchronize method in more than 1 application server (5 messages)
- Posted by: Junyang Bi
- Posted on: August 11 2003 23:19 EDT
Threaded Messages (5)
- Reply by Alex Pisarev on August 12 2003 03:17 EDT
- Is the JNDI variable the unique in two application servers? by Junyang Bi on August 12 2003 23:50 EDT
- Use the DB for this by Barri Jansen on August 13 2003 02:40 EDT
- Reply by Alex Pisarev on August 13 2003 09:45 EDT
- Is the JNDI variable the unique in two application servers? by Junyang Bi on August 12 2003 23:50 EDT
- how to use synchronize method in more than 1 application server by Rob Misek on August 12 2003 11:35 EDT
-
Reply[ Go to top ]
- Posted by: Alex Pisarev
- Posted on: August 12 2003 03:17 EDT
- in response to Junyang Bi
You can do that via common JNDI flag. In your method, you should retreive JNDI variable and check its status. If its true, you should wait until it becomes false. Otherwise, set the flag to true, bind it to JNDI and proceed with the method execution. At the end of the execution, bind a false value to JNDI.
The same effect could be achieved through common Stateful Session bean (which can be replicated between your appservers) or by using common database record.
But I reckon JNDI solution will be the universal one.
Alex -
Is the JNDI variable the unique in two application servers?[ Go to top ]
- Posted by: Junyang Bi
- Posted on: August 12 2003 23:50 EDT
- in response to Alex Pisarev
Hi Alex,
Thank you for your help. But I'm not familiar for the JNDI variable, can you give me the answer?
junyang -
Use the DB for this[ Go to top ]
- Posted by: Barri Jansen
- Posted on: August 13 2003 02:40 EDT
- in response to Junyang Bi
Java and/or J2EE don't provide generic solutions for this. You have to write something yourselve, by using a DB (write a lock entry or something) for this.
Regards
Barri -
Reply[ Go to top ]
- Posted by: Alex Pisarev
- Posted on: August 13 2003 09:45 EDT
- in response to Junyang Bi
Junyang,
You can consider JNDI as a database replacement. When you get an InitialContext, you can easily bind any objects you want to it. For example, you can bind a flag this way:
Context ctx=new InitialContext();
ctx.bind ("my_boolean_flag",new Boolean(true));
If you have a central JNDI which is accessible by both application servers, you can easily retreive the value from any of this servers.
Alex -
how to use synchronize method in more than 1 application server[ Go to top ]
- Posted by: Rob Misek
- Posted on: August 12 2003 11:35 EDT
- in response to Junyang Bi
Hi junyang Bi,
If you would like to cluster a large (or small ;-) amount of data across multiple appserver nodes take a look at Tangosol's Coherence product. Coherence supports cluster-wide locking and event-notification while providing in-memory speed access to your data.
Later,
Rob Misek
Tangosol Coherence: Cluster your Work. Work your Cluster.
Coherence Forums.