Link to home
Start Free TrialLog in
Avatar of illusionz70
illusionz70

asked on

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... !!!!
Avatar of Mayank S
Mayank S
Flag of India image

What is it that you want the listener classes to do? And what is the connection program doing? Please explain their functionalities.
Avatar of GrandSchtroumpf
GrandSchtroumpf

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.
ASKER CERTIFIED SOLUTION
Avatar of Webstorm
Webstorm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of illusionz70

ASKER

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 .
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...???