• 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

Stopping Thread when we force stop the application in weblogic

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I have an application deployed in weblogic. I have thread that starts on weblogic start. I am using Spring configuration, so on load of the class, thread also gets started, since the thread start method is in constructor of the class. But when I try to force stop the application in weblogic, the thread keeps on running. The thread wakes up every 1 minute and do the processing.
I know I have to stop the thread by interrupting the blocked state and to protect the loop from further iteration by setting a volatile flag.

if (dxhMonitorThread != null) {
try {
dxhMonitor.threadStop = true;
dxhMonitorThread.interrupt();
} catch (SecurityException e) {
System.out.println("DXH Monitor Thread Interrupted/Stopped ");
}
}
dxhMonitorThread = null;

But I am confused about where to put this code or from where I have to call the stop method. I am not sure about the exit point.

Thanks for the help
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One option would be to just make sure your Runnable handles interruption appropriately and an ExecutorService to submit it for execution.
That way you could use ExecutorService#shutdown() / ExecutorService#shutdownNow() to stop its execution, which I guess you could call from a shutdown hook, using Runtime#addShutdownHook().
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the same problem in Weblogic 8 and Weblogic 10.

What I found is that if you have a servlet in you deployed .ear file that does :



then...
the servlet will continue writing to sysout after you stop the ear.
the servlet will continue writing to sysout after you undeploy the ear.
the servlet will finally stop writing when you shutdown the application server.

The proposed shutdown-hook solution is not useful here because the hook will only be called upon server shutdown.

Anyone know of a hook that can be called at the moment of the application-stop (or at the very least at the moment of the application-undeploy) ?

Seems to me a pretty huge breach in weblogic, the fact that your application will effectively keep running after you stop it and even after you undeploy it !

Comments & suggestions are welcome ...
 
steph maybe
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
another thing ...

if your servlet does this :


Then upon application-undeploy, the servlet will keep writing until we reach time t, but then once we reach time t, the servlet will stop writing, leave the while loop, and ... do nothing ! That is, it does not call executeAction().

So what exactly is application-undeploy ?
It leaves your application running, sort of ?
It allows certain actions (looping, writing to files), but not others ?

I'll be very grateful to anyone who can explain this to me, I've gone through all of Oracle-BEA-Weblogic docs and can't find a straight answer.
 
steph maybe
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried the same test and it seems that executeAction() can execute after application-undeploy (maybe it depends on what that method does).

my application is able to query an oracle database via JDBC and print the results in a file AFTER having been "undeployed" in Weblogic !



seems to me that it's unsafe to undeploy an application in Weblogic unless you follow that by stopping/restarting the application server.

anyone care to share their experience with this or any explanations ?
anyone have a suggestion on how to make my application stop upon undeploy ?

 
steph maybe
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
found a partial solution / work-around.

recall that i was looking for a hook that's launched at application-stop (similar to the Runtime shutdown hook that is called upon server-stop).
in other words, a method that's automatically called upon application-stop.

it turns out that application-stop launches the Garbage Collector, or at least it does in the tests that i've done.
i think the GC will call the destroy() method on all your loaded servlets.

so it suffices to add a destroy() method to a servlet, and there you have your application-stop hook.

so i wrote a simple servlet that launches upon application-startup (web.xml : <load-on-startup>1</load-on-startup>) and its destroy() method redefines a static boolean in a Singleton class that i've added as a condition to my while loop above.

when i do an application-stop in weblogic, the GC is launched, the destroy() is called, the boolean is redefined, the while loop stops, and we're golden.


reply
    Bookmark Topic Watch Topic
  • New Topic