Solved

can multiple processes access another class exclusively

Posted on 2004-03-28
5
188 Views
Last Modified: 2010-08-05
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
Comment
Question by:illusionz70
5 Comments
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
What is it that you want the listener classes to do? And what is the connection program doing? Please explain their functionalities.
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
Comment Utility
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
 
LVL 13

Accepted Solution

by:
Webstorm earned 175 total points
Comment Utility
>> 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
 
LVL 4

Author Comment

by:illusionz70
Comment Utility
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
 
LVL 4

Author Comment

by:illusionz70
Comment Utility
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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now