You have it the wrong way around. setDaemon(true) allows the JVM to exit. The JVM will not exit while there are non-Daemon threads running.
JBoss does a halt anyway, so this isn't really a problem. Regards, Adrian On Thu, 2003-09-25 at 18:24, JD Brennan wrote: > setDaemon(true) will cause the thread to exit on shutdown, > but will it cause the thread to exit when the MBean is stopped > or undeployed? > > We just implemented logic in the stop() method to interrupt > the threads so they will exit when JBoss stops the MBean. > > JD > > -----Original Message----- > From: Andreas Mecky [mailto:[EMAIL PROTECTED] > Sent: Thursday, September 25, 2003 3:20 AM > 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 > > > ------------------------------------------------------- > 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 -- xxxxxxxxxxxxxxxxxxxxxxxx Adrian Brock Director of Support Back Office JBoss Group, LLC xxxxxxxxxxxxxxxxxxxxxxxx ------------------------------------------------------- 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
