Where do you set running = false?

Change running to a member (and probably mark it 'volatile' too)
and then set it to false in stopService().

-- 
Danny Yates
 


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: 25 September 2003 09:09
To: jboss mailing list
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


_____________________________________________________________________ 
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