• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Synchronization across diff JVM

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you synchronize a section of code that can only be run by one thread
on multiple JVMs
 
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll need an artificial mechanism: Synchronization is process specific.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's a good external sync, Max? Maybe a database? This seems really clunky:

start transaction
read a row for update
do the synchronized code
update the row
end transaction
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stan James:
What's a good external sync, Max? Maybe a database? This seems really clunky:

start transaction
read a row for update
do the synchronized code
update the row
end transaction




The question is "why would you want a synchronization across JVMs"?... Interestingly, in many cases, it is to either protect a service or database.

So... although it is clunky, in many cases, it may be the best thing to do.

Henry
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by George Nan:
How do you synchronize a section of code that can only be run by one thread
on multiple JVMs



A section of code? You can't. Why would you want to? Perhaps you are trying to synchronize access to some specific resource that is shared across multiple JVMs?
 
Max Habibi
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stan James:
What's a good external sync, Max? Maybe a database? This seems really clunky:

start transaction
read a row for update
do the synchronized code
update the row
end transaction




Boy, that's a really excellent question. You could use a shared File, but with virtual file shares and such, you're fishing for trouble there. You could use an external service: say a locking external webservice or EJB. But that's clunky too, and prone to network issues.

I'm amazed to see myself type this: but yes, I'd say a database: with some sort of transactional activity.

What do you think, Stan? I'm very interested in hearing your thoughts.

M
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think this question can be adequately answered until you explain what you're trying to do and why. Often times questions like this are perplexing because without knowledge of your requirements and motivations we can only guess at what an optimal solution is. Furthermore, it's not uncommon for the question to be a result of a misguided attempt at solving a related problem. By understanding the problem that motivates this need we may also be able to offer suggestions that avoid the issue completely.
 
Max Habibi
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure I agree with that, Ken. This is a general problem, and I can see cropping up all over the place: especially as multi clustering and multiprocessing becomes more common.

I think I can recommend the database approach generally, without know the details of exactly why it's necessary to synch across multiple processors. I think this sort of problem is becoming more and more common: I suspect that java 6 or 7 will provide a mechanism to address it.

M
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Multiple processors? I believe they asked about multiple JVMs.
 
Max Habibi
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Multiple processors are superset of multiple JVMs: solve the problem for multiple processors, and you've also solved it across multiple JVMs on a single processor.

Since Java is designed to work consistently across various OSs, and most Unix production machines do use multiple processors, a Java solution to multiple JVMs on the same processor probably isn't very useful.

Practically speaking, it's probably a very safe bet to assume that we're talking multiple processors in most all production grade JVM environments.

-best,
M
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought a single JVM could operate on multiple processors if it used multiple threads?
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm curious about the problem requirements, too. I can imagine (make up) serializing access to a shared physical device but this isn't something I've run into mice elf. And it would be better if the device came with a driver that took care of this for me.

I'd probably try a database option if the app already has a transactional database. DB vendors have spent a lot of time working on concurrency and I'm sure they do it better than I do.
[ March 24, 2006: Message edited by: Stan James ]
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
for access to a shared resource i would not use a database. I would create a server to arbitrate access. probably across RMI.
 
Max Habibi
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stan James:
I'd probably try a database option if the app already has a transactional database. DB vendors have spent a lot of time working on concurrency and I'm sure they do it better than I do.



I have to agree. Still, it *does* seem like we need better answers: probably from the language itself.
[ March 27, 2006: Message edited by: Max Habibi ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic