• Post Reply Bookmark Topic Watch Topic
  • New Topic

Query in Singelton class  RSS feed

 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a singleton class for starting and stopping a process.
Only one instance of process should be created .
So my code goes this way ..


Then i ran a java code in a console to start the thread ..The code was working and listening indefinitely ..
For stopping the process i opened another console and ran a java code to stop the thread i mean it called the "stopThread()" .. but the above process is not stopping ..

I used the following code to start the process


I used the following code to stop the process in a different console
but above process is indefinetly waiting



Please guide me
[ November 26, 2004: Message edited by: srini vasan ]
 
Paul Johnson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I think the problem could be that the java processes are run in 2 seperate JVM's . So in fact when you try to get an instance you are getting a completely different instance because you have one FileListener per JVM.

To Test this theory.
Put a debug/print statement in the getInstance of the thread object.
You effectively need to do interprocess communication to stop the thread.

By running the command java myProgram you are starting a new JVM.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul Johnson,
Thanks now i got the problem ..
So think about this situation .. Normally while starting and stopping any web server's for example.. we can run two different scripts one for starting the server and the other one to stop the server in seperate console's .. So does interprocess Communication comes into picture here ?
 
Paul Johnson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I imagine it must.
Not quite sere of how it works though.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Johnson:
I imagine it must.
Not quite sere of how it works though.


Ok Thanks paul ..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!