Question about sleeping

I have to check at regular intervals for files in a directory and do some work with the files. I want to check every 5 minutes and see if the files have been updated or changed (by some other nonJava process), do some processing on the files and sleep for the next 5 minutes. I was not sure how I can check the files at the regular intervals. Any help is welcome. Thanks.
-kn

Hmmmm...well, I can think of two ways:
1. Use Thread.sleep(int millis)
"(from 1.4 api)Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds. The thread does not lose ownership of any monitors.
Parameters:
millis - the length of time to sleep in milliseconds."
In your case, milliseconds would be 5 (minutes) * 60 (seconds) * 1000 (milliseconds) = 300000
2. Make your program check the files only once and run it every 5 minutes in a cron job. If you don't know what this is or are not on Unix, maybe check out Scheduled Tasks on Windows.
The first option is best for you, probably...
Tarabyte

Similar Messages

  • A question about sleep.

    Two months ago I upgraded (perhaps downgraded is a better term, depending on perspective), anyways changed machines from my trusted 1 Ghz Powerbook G4 Ti to a White MacBook Intel 2.1 Ghz Intel Core 2 Duo.
    My main question here is does the MacBook put itself to sleep when the battery reaches a certain level? My PowerBook always put itself to sleep when the battery went down to around 20% or so. But recently I have discovered that when I leave and have my MacBook running it turns itself off when the battery reaches 0% even after a smc reset and a reformat and reinstall. At least that's what it says when I plug it in and have to turn it on instead of just waking it from sleep. Is this something that is normal now or should it be going to sleep like the PowerBook did? Yes I know - just plug it in before I leave. If I know I am going to be gone a long time I do - sometimes I plan to be gone only a short time but plans change. Plus I believe everyone who can, should save energy when they can.
    I have contacted apple about this problem and several others (now and then the speakers will crackle and unplugging headphones there will be no sound, and keys sticking) and they will be picking up the MB to check it out. Just curious if anyone else has had this/these problems and if you got them fixed.
    *Little Rant* And I have to admit I find the intel machine a bit frustrating and I am totally unimpressed with it. (Final Cut Pro 4/5 doesn't work as well as some other costly PPC apps not working or working poorly). Yes I know, why get a MacBook for doing stuff like that - because I don't do a lot of creating anymore - generally just upkeep and small changes. Not enough to justify the cost difference.
    Also I thought the increased cpu power would make it fly - but I still get the spinning beach ball a lot. Although processing short videos and animations is quicker (obviously 1 Ghz vs 2.1 Ghz) - but I wonder if the 2.1 intel is actually much faster (I mean more than a minute) than the 1.67 ppc - does anyone know?

    Thanks for the input iBod.
    Setting the time to go to sleep when idle is not really the problem. I've been using Macs for about 8 years now and I already know about setting the preferences. This year was my first intel MacBook and it isn't as similar as I thought it would be. Sorry if I wasn't more clear in my earlier post.
    When I do leave it unattended and running it is because it is processing some stuff for me (be it a video, music, downloading, or whatever) as well as for example a project in iwork and/or photoshop is still open so I can just start where I left off when I return.
    The problem I am having is (I am not sure if this is what you mean by "deep sleep") that the computer literally shuts down and I have to push the power button and the MB does a total restart (vs the Powerbook which would just go to sleep so I'd plug it in, press a key and it was exactly where I left off).
    This worries me, as I know hard shut downs (which what this seems like to me) aren't good for a computer at all, plus the possible and probable data loss. It seems to be a step away from having things "Just Work" rather than a step forward.
    I don't suppose you (or anyone else reading this) knows of any script, terminal setting or preference that I could use to put my MB to sleep when the battery reaches a certain low level?
    About final cut 4/5 not working. I didn't mean it that it worked slowly, I meant that it won't even install. When I tried to install it gave some weird video error (can't remember clearly but it was something like 'this machine isn't equipped with agp video card (or something like that) and can't be installed'.
    Thanks again for chipping in though.

  • Question about sleep resume issue

    Hi friends! I have the following question: When I resume my T430 Thinkpad from sleep and is not plugged in instead of bringing back the screen of my last session the computer starts booting. This cause lots of problems especially if I have any unsaved work. I didn't have this problem in the past (after I was pressing the green button my computer was always starting at the session that I left it before I chose SLEEP). I usually don't have this problem if the computer is plugged in. I also noticed that this happens only if the remaining battery time is 2 hours or less (or maybe this is just a coincidence). Has anyone else experienced the same problem? Is there a setting that I can change? Thank you!

    Yes. I have this problem with my T430, but only when I have both the main battery and also the battery "slice" installed. What happens is that after the first battery is run down (the "slice" is run down first), the T430 switches to the other battery (the main battery). If I then suspend the computer, it appears that it tries to maintain the memory during sleep mode using the depleted battery which, of course, results in the same thing as removing the battery while in sleep.
    I've tried to figure out how to contact Lenovo but, despite having an extended support contract, I have been unable to do so. I'm hoping someone here can help or can direct me to where I can find out how to contact Lenovo about what is obviously a flaw in their design.

  • A question about sleep procedure

    I want to create a process that will call a function periodically with a certain repeating time which is decided by another process.
    I write a process with a infinite LOOP, then I use DBMS_LOCK.sleep() to control the repeating time of that function. So I wonder how accurate the sleep() is? I know the accuracy is hundredth of a second. If I set the time is 1.99, will this process really sleep exactly for 1.99 second and then be invoked? Thnaks.

    Hi,
    I don't know the exact accuracy and I suspect that no guarantees are made. However, simple tests show that dbms_lock is accurate to about +/- .01 seconds.
    e.g.
    sqlplus
    SQL> set timing on
    SQL> exec dbms_lock.sleep(1.5555)
    SQL> exec dbms_lock.sleep(1.5555)
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:01.57
    You should dismiss the first result since this includes overhead to cache some stuff (although maybe you need to take that into account too).
    Hope this helps,
    Ravi.

  • Curious question about sleep light.

    Currently loving my new 2011 17" MBP, it's been completely great, no problems at all.
    I'm just curious about one little thing. My sleep light, seems a little dimmer on the right half. Looking at it at different angles seems to make it look "full". I was just wondering if this is the normal?
    Like I said, I love the computer, and I don't plan on returning it because of this, I'm simply curious if this is what it's supposed to look like.
    I'm thinking perhaps there's some dust or something in there affecting how it looks at certain angles.

    I just got the new 15' mbp myself an have had no problems.
    Except the issue you have. Although mine seems like its lost lighting on left side. Its very very minor but I can tell, which bothers me becuase I'v paid $2000 for it brand new for a reason (to look brand new).
    Have you had problems with it since than?
    An also wondering if you could would you exchange it for a brand new one because I do have 14 days to take back?

  • Really silly question about Sleep

    I am accustomed to my old MacBook Pro, which recently died, being put to Sleep by closing the lid.
    I am accustomed to my ancient G4 iMac, where you put it to Sleep by the keyboard combination Command-Option-Eject.
    I just bought a refurbished late-2012 iMac with the Bluetooth keyboard and mouse. Do I have to invoke Sleep by selecting in in the Apple menu, or is there a new keystroke command?
    Thanks in advance,
    --WA

    You can put your Mac to sleep by two ways:
    1. Through a shortcut: hold Option, Command and Eject keys.
    2. Go to  > Sleep.
    Both options will work by the same way because both do the same

  • I just got a new macbook pro and I had a question about sleep vs off.

    When do you turn it off? i hear from alot of people that they never turn it off, rather they keep it on sleep mode, even overnight. What os the best for your macbook?

    One of the reasons that people just sleep it is that OS X is based on the Unix operating system, which was designed for servers, which means the OS was designed to be run 24/7. It has no problem with not being shut down in weeks.
    And in fact that's how I run my Macs. They stay up for weeks, sleeping at night, often they are only restarted if a software update requires it.
    Avoiding a full shutdown has many practical benefits too. You can leave many apps and documents open when you sleep it, and when you wake it, all your work and logins are already open and waiting for you.
    In other words, taking advantage of sleep means you have an "instant-on" computer. You don't need to care how long it takes a computer to boot up, if you hardly ever boot up, and if your own wake-to-work time is basically one or two seconds with no need to re-open anything.
    I and many other Mac users have successfully used sleep-only habits during extended travel. At least a couple times I have left on a trip, carried my MacBook Pro on a plane, across continents and oceans, and trains and buses and walking, and all the way back home, in a single OS X uptime session, never restarting or shutting it down at all. (Although sleeping it during transport, of course.)

  • Really really easy question about sleeping MBP

    I have a macbook pro and i am running a program that cannot save for whatever reason, and i want to know if i can close the screen (putting the computer to sleep, i havent changed any defaults), will my program QUIT causing me to loose all of my work, or will it remain "open" and open with my work the next time i open my screen
    thanks
    ben

    Your program may quit for other reasons which you have no control over.
    Backup and save your data frequently*:
    http://www.macmaps.com/backup.html
    - * Links to my pages may give me compensation.

  • Basic questions about macbook pro + external monitor

    Hi,
    I have some very basic questions about using a Macbook Pro + external display. I don't actually have them but need to know how things works.
    So, here they are:
    1) Can I use the external display as the main display?
    2) Will the external display run with its resolution or with that of the mbook pro?
    3) Somewhere I read that you cannot keep the macbook pro open and get the full resolution of the external display. Is that true ?
    4) Is it dangerous to keep the mbook closed while using the external display?
    5) Does the usage of the external display impact on mbook performance?
    I know...a lot of questions , but would be nice if someone could help me.
    Thanks.

    Hi - I am presently using an external display.
    To answer your questions in sequence:
    1. Yes you can use the external display as your main display. The way to enable that mode is to put your MacBook Pro to sleep, attach the external display. Wake up your MBPro with the lid closed and you will see the external display as you main display. You can alternatively set the external to "Mirror" your notebook by using preferences/display.
    2. The external display will run at its resolution although you can adjust and calibrate it using Preferences/Display.
    3. Not true. You get max resolution on both displays. Of course you may have to tweak as mentioned above.
    4. Not at all. I use this mode all the time. Just make sure you initially set up as mentioned above and your LCD on the MBPro will stay off.
    5. I have not seen any performance degradation whatsoever.
    Hope this helps.

  • Basic questions about programing for J9 VM

    I need to create a java application to run on a Pocket PC 2003 OS and I'm limited to using IBM's Websphere J9 Virtual Machine. I'm new to using java in this capacity and therefore have lots of questions which I'm guessing are pretty basic. Despite my best efforts, I've found very little to help me online. Below are a couple questions I have that I'm hoping someone can help me with. Even better, if you know of any resources that could help me with these and other questions, I'd love to have them. Thanks in advance.
    1. I'm using standard AWT for the GUI but I'm having problems getting frames, dialogs, etc., to come up in anything less then full screen. setSize() and resize() have no effect, even if I extend the frame and override the setMinimumSize, setPreferredSize, setMaximumSize methods. What do I need to do to get a child window to appear in something less than full screen?
    2. I'd like to be able to add menu's to the buttom toolbar (with the keyboard) but have no idea how I would add something to it. Can someone point me in the right direction?
    3. When my application gets an iconified event I go ahead and call a System.exit() to exit the application. This doesn't kill the java VM though, which continues to run in the background (taking up plenty of memory). If I run my application using the J9w.exe so that it runs without the console, then not only does the VM continue to run, but I have no way to stop it (the running program list can't see it). Since each time I run my application it starts a new VM, it only takes a couple of times before I'm out of memory and have to do a soft reset of the PDA to make things right. Can I kill the VM when I kill my application?
    4. I learn best by looking at example code, but have been unable to find any code people are running on J9. I have the GolfScoreTracker installed and running on my PDA, but the jar file contains only the classes. Since it's supposed to be a demo, I had hoped that the source code would be included, is that hoping too much or is the source code available somewhere? In addition, if you know of any applications out there with available source code that are known to run well on a PocketPC J9 environment I'd appreciate the link.

    Hi there, I saw your questions, im currently developing a java pocket pc application as well and here's what i go so far:
    AWT seem to be hard to use on pocket pc, instead i recommend that you use SWT, which is a technology developed by eclipse. It's already installed on the eclipse plugins, you just need to download the jar and dll files for the pocket pc. They are available at: http://www.eclipse.org/downloads/index.php
    I assume that you already have the J9 working on your device. So you only need to copy the SWT.jar file and the swt-win32-3064.dll to the folder containing the .class files on your device.
    Now, on your java IDE(im using eclipse) Add the SWT.jar library to your project which should be on C:/eclipse/plugins/org.eclipse.swt.win32_3.0.2/ws/win32/swt.jar or something like taht depending on your eclipse root.
    Now you are ready to code some SWT, here is a sample program from Carolyn MacLeod, i modified a few things so it could run on the pocket pc but it's almost the same. Once you coded in eclipse run it, then copy the class file from your desktop to your device(There should be like 4 or 5 classes like sample.class, sample$1.class etc. copy all of them) where you put the jar and dll files(If program does not run you may try to rename the dll file for swt-win32-3050.dll instead of 3064.dll). Now after you have everything set up you need to create the lnk file in order to run the program. On your desktop create a new textfile and write the following on it:
    255#"\Archivos de Programa\J9\PPRO10\bin\j9w.exe" "-jcl:PPRO10" "-cp" "\My
    Documents\Java\swt.jar" ;\My Documents\Java" sample
    Paths depend on your install, and the place where you put your classes and jar file. path for j9w is usually "\Program Files\J9\PPRO10\bin\j9w.exe", and the last word should be the classname.
    Currently this form only displays an image on a canvas, click on the browse button and choose a pic and it will display on the canvas. Im trying to connect the form to an oracle database but no success yet on the device.
    Hope it helps, if you have any questions about the code or something, and I know the answer, please feel free to ask.
    See ya
    import org.eclipse.swt.*;
    import org.eclipse.swt.widgets.*;
    import org.eclipse.swt.layout.*;
    import org.eclipse.swt.events.*;
    import org.eclipse.swt.graphics.*;
    public class sample {
    static Shell shell;
    static Display display;
    static Text dogName;
    static Text textdb;
    static Combo dogBreed;
    static Canvas dogPhoto;
    static Image dogImage;
    static List categories;
    static Text ownerName;
    static Text ownerPhone;
    static String[] FILTER_EXTS = {"*.jpg"};
    public static void main(String[] args) {
    display = new Display();
    shell = new Shell(display, SWT.RESIZE | SWT.CLOSE);
    Menu menu = new Menu(shell, SWT.BAR);
    shell.setText("Dog ShowS Entry");
    shell.setMenuBar(menu);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    shell.setLayout(gridLayout);
    new Label(shell, SWT.NONE).setText("Dog's NameS:");
    dogName = new Text(shell, SWT.SINGLE | SWT.BORDER);
    GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.horizontalSpan = 2;
    gridData.widthHint = 60;
    dogName.setLayoutData(gridData);
    new Label(shell, SWT.NONE).setText("Breed:");
    dogBreed = new Combo(shell, SWT.NONE);
    dogBreed.setItems(new String [] {"Collie", "Pitbull", "Poodle", "Scottie"});
    dogBreed.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    Label label = new Label(shell, SWT.NONE);
    label.setText("Categories");
    label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    new Label(shell, SWT.NONE).setText("Photo:");
    dogPhoto = new Canvas(shell, SWT.BORDER);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.widthHint = 60;
    gridData.verticalSpan = 3;
    dogPhoto.setLayoutData(gridData);
    dogPhoto.addPaintListener(new PaintListener() {
    public void paintControl(final PaintEvent event) {
    if (dogImage != null) {
    event.gc.drawImage(dogImage, 0, 0);
    categories = new List(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
    categories.setItems(new String [] {
    "Best of Breed", "Prettiest Female", "Handsomest Male",
    "Best Dressed", "Fluffiest Ears", "Most Colors",
    "Best Performer", "Loudest Bark", "Best Behaved",
    "Prettiest Eyes", "Most Hair", "Longest Tail",
    "Cutest Trick"});
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
    gridData.widthHint = 60;
    gridData.verticalSpan = 4;
    int listHeight = categories.getItemHeight() * 12;
    Rectangle trim = categories.computeTrim(0, 0, 0, listHeight);
    gridData.heightHint = trim.height;
    categories.setLayoutData(gridData);
    Button browse = new Button(shell, SWT.PUSH);
    browse.setText("BrowsePic");
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.widthHint = 60;
    browse.setLayoutData(gridData);
    browse.addSelectionListener(new SelectionAdapter() {
         public void widgetSelected(SelectionEvent event) {
              FileDialog dialog = new FileDialog(shell, SWT.OPEN);
              dialog.setFilterExtensions(new String[] {"*.*"});
              String fileName = dialog.open();
    if (fileName != null) {
    dogImage = new Image(display, fileName);
    shell.redraw();
    Button delete = new Button(shell, SWT.PUSH);
    delete.setText("No action");
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    gridData.widthHint = 60;
    delete.setLayoutData(gridData);
    delete.addSelectionListener(new SelectionAdapter() {
    public void widgetSelected(SelectionEvent event) {
    Button enter = new Button(shell, SWT.PUSH);
    enter.setText("No action");
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
    gridData.horizontalSpan = 3;
    enter.setLayoutData(gridData);
    enter.addSelectionListener(new SelectionAdapter() {
    public void widgetSelected(SelectionEvent event) {
         shell.open();
         while (!shell.isDisposed()) {
              if (!display.readAndDispatch())
                   display.sleep();
         display.dispose();
    if (dogImage != null) {
    dogImage.dispose();
    }

  • Questions about ActiveX Bridge and SWT

    Hi !
    I found few weeks ago the www.reallyusefulcomputing.com site answering my question about Java & Macro of MSWord. Now I've found two steps that I am not able to overcome.
    First, when I build a simple application and I have internal libraries to use, am I compelled to place the jars in the lib/ext directory of the Java Runtime Directory? I have many difficulties in placing a convenient class-path in the manifest file. Why does the application ignore the manifest string?
    The second problem (and the biggest one) is that I am trying to build an SWT java-bean-application but I have problems during runtime. Is it possible to use this technology for my software or am I compelled to use AWT and SWING?
    I really hope you can help me.
    Thank you in advance.

    hi,
    I have to catch events from excel sheet in my java code..events like some change in value or a click of some user defined button etc.I have written th follwoing code but it does not gives me any event.It simply opens the specified file in the excel in a seperate window.but when i click on the sheet or change some value no event is captured by my code....can ne one pls tell me how to go about it....
    public class EventTry2 {
         private Shell shell;
         private static OleAutomation automation;
         static OleControlSite controlSite;
         protected static final int Activate = 0x00010130;
         protected static final int BeforeDoubleClick = 0x00010601;
         protected static final int BeforRightClick = 0x000105fe;
         protected static final int Calculate = 0x00010117;
         protected static final int Change = 0x00010609;
         protected static final int Deactivate = 0x000105fa;
         protected static final int FollowHyperlink = 0x000105be;
         protected static final int SelectionChange = 0x00010607;
         public void makeVisible()
              Variant[] arguments = new Variant[1];
              arguments[0]=new Variant("true");
              //Visible---true
              automation.setProperty(558,arguments);
              //EnableEvent--true
              boolean b =automation.setProperty(1212,arguments);
            System.out.println(b);
             public Shell open(Display display){
             this.shell=new Shell(display);
              this.shell.setLayout(new FillLayout());
              Menu bar = new Menu(this.shell,SWT.BAR);
              this.shell.setMenuBar(bar);
              OleFrame frame = new OleFrame(shell,SWT.NONE);
            File file= new File("C:\\Book1.xls");
              try{
              controlSite =  new OleControlSite(frame, SWT.NONE, "Excel.Application");
              this.shell.layout();
              boolean a2=true;
              a2=(controlSite.doVerb(OLE.OLEIVERB_SHOW|OLE.OLEIVERB_OPEN|OLE.OLEIVERB_UIACTIVATE|OLE.OLEIVERB_HIDE|OLE.OLEIVERB_PROPERTIES|OLE.OLEIVERB_INPLACEACTIVATE)== OLE.S_OK);
              System.out.println("Activated::\t"+a2);
            }catch(SWTException ex)
                 System.out.println(ex.getMessage());
                 return null;
              automation = new OleAutomation(controlSite);
              //make the application visible
              makeVisible();
              System.out.println("Going to create Event listener");
              OleListener eventListener=new OleListener(){
                   public void handleEvent(OleEvent event){
                        System.out.println("EVENT TYPE==\t"+event.type);
                   switch(event.type){
                   case Activate:{
                        System.out.println("Activate Event");
                   case BeforeDoubleClick:{
                        System.out.println("BeforeDoubleClick Event");
                   case BeforRightClick:{
                        System.out.println("BeforeRightClick Event");
                   case Calculate:{
                        System.out.println("Calculate Event");
                   case Change:{
                        System.out.println("Change Event");
                   case Deactivate:{
                        System.out.println("DeActivate Event");
                   case FollowHyperlink:{
                        System.out.println("Activate Event");
                   case SelectionChange:{
                        System.out.println("Activate Event");
                        Variant[] arguments = event.arguments;
                        for(int i=0;i<arguments.length;i++)
                             System.out.println("@@");
                             arguments.dispose();
              System.out.println("outside");
              OleAutomation sheetAutomation=this.openFile("C:\\Book1.xls");
              controlSite.addEventListener(sheetAutomation,Activate,eventListener);
              controlSite.addEventListener(sheetAutomation,BeforeDoubleClick,eventListener);
              controlSite.addEventListener(sheetAutomation,BeforRightClick,eventListener);
              controlSite.addEventListener(sheetAutomation,Calculate,eventListener);
              controlSite.addEventListener(sheetAutomation,Change,eventListener);
              controlSite.addEventListener(sheetAutomation,Deactivate,eventListener);
              controlSite.addEventListener(sheetAutomation,FollowHyperlink,eventListener);
              controlSite.addEventListener(sheetAutomation,SelectionChange,eventListener);
              shell.open();
              return shell;
         public OleAutomation openFile(String fileName)
              Variant workbooks = automation.getProperty(0x0000023c);//get User Defined Workbooks
              Variant[] arguments = new Variant[1];
              arguments[0]= new Variant(fileName);
              System.out.println("workbooks::\t"+workbooks);
              IDispatch p1=workbooks.getDispatch();
              int[] rgdispid = workbooks.getAutomation().getIDsOfNames(new String[]{"Open"});
              int dispIdMember = rgdispid[0];
              Variant workbook = workbooks.getAutomation().invoke( dispIdMember, arguments );
              System.out.println("Opened the Work Book");
              try {
                   Thread.sleep(500);
              } catch (InterruptedException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              int id = workbook.getAutomation().getIDsOfNames(new String[]{"ActiveSheet"})[0];
              System.out.println(id);
              Variant sheet = workbook.getAutomation().getProperty( id );
              OleAutomation sheetAutomation=sheet.getAutomation();
              return(sheetAutomation);
         * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              Display display=new Display();
              Shell shell=(new EventTry2()).open(display);
              while(!shell.isDisposed()){
                   if(!display.readAndDispatch()){
                        display.sleep();
              controlSite.dispose();
              display.dispose();
              System.out.println("-----------------THE END-----------------------------");

  • Question about Runtime.exec

    Rob,
    Thanks for your help.
    I asked a question about a weird Exception on Nov 14, and you told me that I am
    using Runtime.exec to start an external process, and that process is crashing.
    I am a green-hand on Weblogic, and I am trying to enhancing a project developped
    by another person, so I am not familiar with some concepts yet.
    Could you please give me some simple explanation about Runtime.exec and external
    process?
    I found two methods that uses "Runtime" from two classes as following, could you
    help me to see whether or not there is something wrong with the usage of Runtime?
    Thank you very much.
    private int runShellCommand(String command) {
    int exitVal = -1;
    try {
    File runDir = new File(runDirectory);
    String[] env = new String[0];
    Runtime rt = Runtime.getRuntime();
                   double start = System.currentTimeMillis();
    Process proc = rt.exec(command, env, runDir);
    // Capture output in separate thread
    ThreadedStreamReader error = new ThreadedStreamReader(proc.getErrorStream(),
    "ERROR");
    ThreadedStreamReader output = new ThreadedStreamReader(proc.getInputStream(),
    "OUTPUT");
    error.start();
    output.start();
    exitVal = proc.waitFor();
    if (logger.isDebugEnabled()) {
         double runtime = (System.currentTimeMillis() - start) / 1000.0;
         logger.info("run " + runId + " " + command + " finished in " + runtime
    + " seconds");
    } catch (IOException e) {
    logger.fatal("DOE-2 failed \n" + e.getMessage());
    } catch (InterruptedException e) {
    e.printStackTrace();
    return exitVal;
    public static void main(String[] args) throws Exception, InterruptedException
    final Doe2MessageServer server = new Doe2MessageServer();
    while(!connected) {
    Thread.sleep(1000);
    logger.info("Attempting to start JMS service ...");
                   try {
              server.init();
                   } catch (Exception ex) {
    // shutdown hook to close JMS connection
    Runtime.getRuntime().addShutdownHook(
    new Thread() {
    public void run() {
    server.finalize();
    server.receiveMessage();

    Runtime.exec is a J2SE API. It's not really specific to WLS.
    You can read about it here:
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Runtime.html
    It looks like you are starting a JMS Server in a separate process and
    that process is crashing.
    (You could of course just use WLS's JMS Server instead :>)
    -- Rob
    Iris Qu wrote:
    Rob,
    Thanks for your help.
    I asked a question about a weird Exception on Nov 14, and you told me that I am
    using Runtime.exec to start an external process, and that process is crashing.
    I am a green-hand on Weblogic, and I am trying to enhancing a project developped
    by another person, so I am not familiar with some concepts yet.
    Could you please give me some simple explanation about Runtime.exec and external
    process?
    I found two methods that uses "Runtime" from two classes as following, could you
    help me to see whether or not there is something wrong with the usage of Runtime?
    Thank you very much.
    private int runShellCommand(String command) {
    int exitVal = -1;
    try {
    File runDir = new File(runDirectory);
    String[] env = new String[0];
    Runtime rt = Runtime.getRuntime();
                   double start = System.currentTimeMillis();
    Process proc = rt.exec(command, env, runDir);
    // Capture output in separate thread
    ThreadedStreamReader error = new ThreadedStreamReader(proc.getErrorStream(),
    "ERROR");
    ThreadedStreamReader output = new ThreadedStreamReader(proc.getInputStream(),
    "OUTPUT");
    error.start();
    output.start();
    exitVal = proc.waitFor();
    if (logger.isDebugEnabled()) {
         double runtime = (System.currentTimeMillis() - start) / 1000.0;
         logger.info("run " + runId + " " + command + " finished in " + runtime
    + " seconds");
    } catch (IOException e) {
    logger.fatal("DOE-2 failed \n" + e.getMessage());
    } catch (InterruptedException e) {
    e.printStackTrace();
    return exitVal;
    public static void main(String[] args) throws Exception, InterruptedException
    final Doe2MessageServer server = new Doe2MessageServer();
    while(!connected) {
    Thread.sleep(1000);
    logger.info("Attempting to start JMS service ...");
                   try {
              server.init();
                   } catch (Exception ex) {
    // shutdown hook to close JMS connection
    Runtime.getRuntime().addShutdownHook(
    new Thread() {
    public void run() {
    server.finalize();
    server.receiveMessage();

  • Hi , i'm new here and i would like to ask a question about iPad 2 . Well , actually when i hold my finger on any icon , its not jiggling , i need to fix the icons . May i know what can i do in this case ? thank you in advance ,

    Hi , i'm new here and i would like to ask a question about iPad 2 . Well , actually when i hold my finger on any icon , its not jiggling , i need to fix the icons . May i know what can i do in this case ? thank you in advance ,

    Try a reset. Hold the Sleep and Home button down for about 10 seconds until you see the Apple logo. Ignore the red slider.

  • Question about servlet architecture

    Hello,
    I have a question about Web Application / servlet architecture and development, and haven't had any luck finding an answer so far. My plan must be either unusual, or wrong, or both, so I'm hoping the community here could point me in the right direction.
    I have quite a bit of background in OSGi, but very little in servlets. I know my architecture would work with something such as sever-side Equinox, but for the open source project I'm contemplating, I think that the more mainstream Tomcat/servler route would be better -- assuming it can be done. Here is a rather simplified scenario:
    There is a class, Manager. It could be a Java class that implements Runnable, or a non-HTTP servlet (GenericServlet?), but somehow it should be configured such that it runs as soon as Tomcat starts.
    When Manager runs, it instantiates its primary member variable: Hashtable msgHash; mshHash will map Strings (usernames) to ArrayList<String> (list of messages awaiting that user). Manager also has two primary public methods: addMsg() and getMsgs().
    The pseudocode for addMsg is:
    void addMsg(String username, String msg) {
    if username=="*" { for each msgList in msgHash { msgList.add(msg) } return;
    if username not in msgHash { msgHash.add(username, new ArrayList<String>) }
    msgHash[username].add(msg)
    And for getMsgs():
    String getMsgs(username) {
    String s = "";
    for each msg in msgHash[username] { s = s + msg; }
    return s;
    Once Manager has started, it starts two HTTP Servlets: Sender and Receiver, passing a reference back to itself as it creates the servlets.
    The HTML associated with Sender contains two text inputs (username and message) and a button (send). When the send button is pressed and data is POSTed to Sender, Sender takes it and calls Manager.addMsg(username.value, message.value);
    Receiver servlet is display only. It looks in the request for HTTP GET parameter "username". When the request comes in, Receiver calls Manager.getMsgs(username) and dumps the resulting string to the browser.
    In addition to starting servlets Sender and Receiver, the Manager object is also spawning other threads. For example, it might spawn a SystemResourceMonitor thread. This thread periodically wakes up, reads the available disk space and average CPU load, calls Manager.addMsg("*", diskAndLoadMsg), and goes back to sleep for a while.
    I've ignored the synchronization issues in this example, but during its lifecycle Manager should be idle until it has a task to do, using for example wait() and notify(). If ever addMsg() is called where the message string is "shutdown", Manager's main loop wakes up, and Manager shuts down the two servlets and any threads that it started. Manager itself may then quit, or remain resident, awaiting a command to turn things back on.
    Is any of this appropriate for servlets/Tomcat? Is there a way to do it as I outlined, or with minor tweaks? Or is this kind of application just not suited to servlets, and I should go with server-side Equinox OSGi?
    Thanks very much for any guidance!
    -Mike

    FrolfFla wrote:
    Hello,
    I have a question about Web Application / servlet architecture and development, and haven't had any luck finding an answer so far. My plan must be either unusual, or wrong, or both, so I'm hoping the community here could point me in the right direction.
    I have quite a bit of background in OSGi, but very little in servlets. I know my architecture would work with something such as sever-side Equinox, but for the open source project I'm contemplating, I think that the more mainstream Tomcat/servler route would be better -- assuming it can be done. Here is a rather simplified scenario:
    There is a class, Manager. It could be a Java class that implements Runnable, or a non-HTTP servlet (GenericServlet?), but somehow it should be configured such that it runs as soon as Tomcat starts.You can configure a servlet to be invoked as soon as Tomcat starts. Check the tomcat documentation for more information on that (the web.xml contains such servlets already though). From this servlet you can start your Manager.
    >
    When Manager runs, it instantiates its primary member variable: Hashtable msgHash; mshHash will map Strings (usernames) to ArrayList<String> (list of messages awaiting that user). Manager also has two primary public methods: addMsg() and getMsgs().
    The pseudocode for addMsg is:
    void addMsg(String username, String msg) {
    if username=="*" { for each msgList in msgHash { msgList.add(msg) } return;
    if username not in msgHash { msgHash.add(username, new ArrayList<String>) }
    msgHash[username].add(msg)
    And for getMsgs():
    String getMsgs(username) {
    String s = "";
    for each msg in msgHash[username] { s = s + msg; }
    return s;
    Once Manager has started, it starts two HTTP Servlets: Sender and Receiver, passing a reference back to itself as it creates the servlets. Not needed. You can simply create your two servlets and have them invoked through web calls, Tomcat is the only one that can manage servlets in any case. Servlets have a very short lifecycle - they stay in memory from the first time they are invoked, but the only time that they actually do something is when they are called through the webserver, generally as the result of somebody running the servlet through a webbrowser, either by navigating to it or by posting data to it from another webpage. The servlet call ends as soon as the request is completed.
    >
    The HTML associated with Sender contains two text inputs (username and message) and a button (send). When the send button is pressed and data is POSTed to Sender, Sender takes it and calls Manager.addMsg(username.value, message.value);
    Receiver servlet is display only. It looks in the request for HTTP GET parameter "username". When the request comes in, Receiver calls Manager.getMsgs(username) and dumps the resulting string to the browser.This states already that you are going to run the servlets through a browser. You run "Sender" by navigating to it in the browser. You run "Receiver" when you post your data to it. Manager has nothing to do with that.
    >
    In addition to starting servlets Sender and Receiver, the Manager object is also spawning other threads. For example, it might spawn a SystemResourceMonitor thread. This thread periodically wakes up, reads the available disk space and average CPU load, calls Manager.addMsg("*", diskAndLoadMsg), and goes back to sleep for a while.Since you want to periodically run the SystemResourceMonitor, it is better to use a Timer for that in stead of your own thread.
    >
    I've ignored the synchronization issues in this example, but during its lifecycle Manager should be idle until it has a task to do, using for example wait() and notify(). If ever addMsg() is called where the message string is "shutdown", Manager's main loop wakes up, and Manager shuts down the two servlets and any threads that it started. Manager itself may then quit, or remain resident, awaiting a command to turn things back on.
    Is any of this appropriate for servlets/Tomcat? Is there a way to do it as I outlined, or with minor tweaks? Or is this kind of application just not suited to servlets, and I should go with server-side Equinox OSGi?
    Thanks very much for any guidance!
    -MikeI don't see anything that cannot be done in a normal java web environment, as long as you are aware of how servlets operate.

  • 5th Generation 80GB iPOD - Questions about functionality

    All - I have a new 80GB video iPOD. The question I have is if I leave it just sit on my desk overnight and not plugged into my PC or power, I come in the next morning and go to use it and it seems as though it is shutdown. I press the button to turn it on, an Apple appears and it boots up. After that it appears to be fine, I am just curious if this is normal or not? Thanks in advance!

    The iPod Nano and the Fifth Generation iPods have a feature called hibernation. Quote: "This allows the iPod to go into a power conservation mode after 14 hours of inactivity but resume operation in the same state as when it was last used. When the iPod wakes from hibernation, you will see the Apple logo displayed for a moment before the menu appears": iPod: About Sleep, Deep Sleep, Hibernation, and Sleep Timer

Maybe you are looking for

  • Report Output is not same as R/3 4.7 and ECC6 ( sort issue)

    Dear Experts, I have a problem with external sort used in the program. due to that report output records are not in the same order. For example, i am extracting data from BSEG with fields company code, fiscal year, document no, item no, amount and GL

  • Short Dump Error while executing the DTP

    Hello Experts, I am facing an issue with DTP. Data has been loaded to PSA successfully but while executing the DTP for loading from PSA to DSO (WO) throwing a short dump RAISE_EXCEPTION. Short text     Exception condition "NO_DS_LG_FOUND" raised. "RA

  • RG1 Functionality

    Dear Friends, We have not used the RG1 functionality in the past. Now for the new plant role out we would like to use the RG1 functionality. Is the standard report provided by SAP sufficient. Do we need a custom report to print RG1 Can you help me wh

  • HP4250n Printer and Forms printing to wrong tray

    OK, I've tried everything I can think of... here's the code: ^job PATFORM -zPHAM01P -atjoff -ati4 -c1 Issue: -ati4 on the HP 4250n This should print from tray 2 on the printer, but it's wanting to do a manual feed from tray one. Works fine on every o

  • Localhost db testing

    I am trying to test locally with some sql/php code.  I am familiar with php/sql, but not with using workbench, or local hosting.  so I set up a site called localhost, and i set "connect using:" to local/network.  i set the web url to 127.0.0.1/.  I w