Not true.

Marking a thread as a daemon simply tells the JVM how to handle the thread
at shutdown. Once the JVM gets to a state where the only threads running are
ALL daemon threads, it will shut down. The thread which calls main() is NOT
a daemon thread, so this situation can only occur once main() has returned.
Essentially, once main() has returned, the JVM waits for all NON-daemon
threads to complete before terminating all the remaining daemon threads and
then exiting.

A thread can be stopped regardless of whether it is a daemon or not.
(Strictly, a thread cannot be forcibly stopped - it must stop itself by
returning from its run() method).

Besides, Harm does do setDaemon(true) immediately before starting the
thread.

Dan.

-- 
Danny Yates
 


-----Original Message-----
From: Andreas Mecky [mailto:[EMAIL PROTECTED] 
Sent: 25 September 2003 11:20
To: [EMAIL PROTECTED]
Subject: Re: [JBoss-user] mbean question


You must use setDaemon(true);
Now your thread is generated as a child process of your thread and
can be stopped by the JVM. Default is false and then the thread
just lives on.

HTH

Andreas

----- Original Message -----
From: <[EMAIL PROTECTED]>
To: "jboss mailing list " <[EMAIL PROTECTED]>
Sent: Thursday, September 25, 2003 10:08 AM
Subject: [JBoss-user] mbean question


> Hi all,
>
> I'm trying to write a basic MBean.
> This Mean runs a Thread which checks the file system for new files. If a
> new file is found it should perform some action.
>
> My problem however is that whenever I undeploy, or stop the MBean using
> the jmx-console application, the MBean keeps running.
>
> I have no idea what I'm doing wrong here.
>
> Below is my code. Could somebody please tell me what it is that I'm doing
> wrong here?
>
> Thanks a lot,
>
> Harm de Laat
> Informatiefabriek
> The Netherlands
>
>
> package nl.informatiefabriek.jmxlizard;
>
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.FileOutputStream;
> import java.io.IOException;
> import java.util.Vector;
>
> import org.jboss.system.ServiceMBeanSupport;
>
> /**
>  * @author harm
>  */
> public class JBossLizard
>         extends ServiceMBeanSupport
>         implements JBossLizardMBean, Runnable {
>
>         private Thread lizard;
>
>         public JBossLizard() {
>         }
>
>         public String getName() {
>                 return "JBossJMXLizard";
>         }
>
>         /* (non-Javadoc)
>          * @see java.lang.Runnable#run()
>          */
>         public void run() {
>
>                 boolean running = true;
>                 while (running) {
>                         /* wait for interval milliseconds */
>                         sleep(interval);
>
>                         /* do some checking */
>                         File checkDir = new File(absoluteCheckPath);
>                         if (!checkDir.exists()) {
>                                 log.warn(
>                                         "Directory does not exist: " +
> checkDir.getAbsolutePath());
>                                 sleep(1000 * 5);
>                                 // we wait for five seconds to avoid a
> huge system load
>                                 continue;
>                         }
>
>                         if (!checkDir.isDirectory()) {
>                                 log.warn(
>                                         "Directory: "
>                                                 +
> checkDir.getAbsolutePath()
>                                                 + "is not a directory.");
>                                 sleep(1000 * 5);
>                                 continue;
>                         }
>
>                         /* retrieve the listing */
>                         String[] dirlist1 = checkDir.list();
>                         for (int i = 0; i < dirlist1.length; i++) {
>                                 /* don't touch hidden files */
>                                 if (dirlist1[i].startsWith(".")) {
>                                         // System.out.println("Hidden
> file... Leaving it untouched: " + dirlist1[i]);
>                                         break;
>                                 }
>
>                                 /* get file extension */
>                                 int index = dirlist1[i].lastIndexOf('.');
>                                 String checkFileExtension =
>                                         dirlist1[i]
>                                                 .substring(index + 1,
> dirlist1[i].length())
>                                                 .toLowerCase();
>                                 System.out.println(
>                                         "File extension is: " +
> checkFileExtension);
>                                 /* see if it is a file we should process
> */
>                                 if (checkFileExtension
>                                         .equals(this
> .getFileExtension().toLowerCase())) {
>                                         System.out.println(
>                                                 "This is the correct file
> extension.");
>                                         /* Create a file handler */
>                                         File f = new File(checkDir,
> dirlist1[i]);
>
>                                         // process the file here!
>                                 }
>
>                         }
>                 }
>                 System.out.println("Lizard stopped...");
>         }
>
>         private void sleep(long howlong) {
>                 try {
>                         Thread.sleep(howlong);
>                 } catch (Exception e) {
>                 }
>         }
>
>         /* MBean methods */
>         protected void startService() throws Exception {
>                 // Create a new thread with this monitor
>                 lizard = new Thread(this, "JBossMonitor");
>                 // Set it as a daemon
>                 lizard.setDaemon(true);
>                 // start the thread
>                 lizard.start();
>         }
>
>         protected void stopService() {
>                 lizard.interrupt();
>         }
> }
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/jboss-user



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user


_____________________________________________________________________ 
Notice to recipient: 
The information in this internet e-mail and any attachments is confidential
and may be privileged. It is intended solely for the addressee. If you are
not the intended addressee please notify the sender immediately by
telephone. If you are not the intended recipient, any disclosure, copying,
distribution or any action taken or omitted to be taken in reliance on it,
is prohibited and may be unlawful. 

When addressed to external clients any opinions or advice contained in this
internet e-mail are subject to the terms and conditions expressed in any
applicable governing terms of business or client engagement letter issued by
the pertinent Bank of America group entity. 

If this email originates from the U.K. please note that Bank of America,
N.A., London Branch, Banc of America Securities Limited and Banc of America
Futures Incorporated are regulated by the Financial Services Authority.
_____________________________________________________________________ 




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to