• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

can multiple processes access another class exclusively

hi,
  i have three listener programs running in 3 consoles which listen to different queues.now i have a conection program which i call from my 3 listeners.the problem is that only 1 connection must be made at one time.i tried implementing the connection class as a singleton,but it doesnt work as the 3 listeners operate as 3 diff processes(my understanding).however if i implement all 3 listeners in 1 single program and start 1 program in console then the singleton works fine. so my question is is there a way i can synchronize the connection class from 3 listener programs running seperately in different consoles???  
maybe my understanding is wrong.excuse me if it is.

any help will be highly appreciated... !!!!
0
illusionz70
Asked:
illusionz70
1 Solution
 
Mayank SAssociate Director - Product EngineeringCommented:
What is it that you want the listener classes to do? And what is the connection program doing? Please explain their functionalities.
0
 
GrandSchtroumpfCommented:
your 3 programs are running in their own environment.
it's like having them running on 3 different computers.
if you want them to communicate, you'll need some kind of client/server architecture.
you could use RMI to acheive that.
but if it's only to obtain a lock on some process, you could simply use a "file lock".
before your program makes a connection, it can check if the file exists.
if the file does not exist, create a file make your connection and delete the file when you are done.
if the files exists, then wait for it to be deleted by the program that has the lock.
0
 
WebstormCommented:
>> but if it's only to obtain a lock on some process, you could simply use a "file lock".
Some synchronization problem will happen :
  P1: file doesn't exist (true)
                     P2:  file doesn't exist (true)
  P1: create the file, use the connection
                     P2: create the file, use the connection

The solution is to use RMI, and use synchronized methods to access the connection.



0
 
illusionz70Author Commented:
but the connection program is a .java file as well and i need an object or instance of the connection.java ad only 1 listener.java must be able to get access to that instance at a time.is this possible with file locks?????

thanks..for all replies and sorri for my late reply .
0
 
illusionz70Author Commented:
File locks work on 1.4 ...i am aloowed to use only 1.3.1 . do i have any alternate options or is it possible to import the filelock library in 1.3.1.

i think a filelock server should go well as different processes can get the lock on file by calling this dedicated server...!!!
ne thoughts...???
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now