Need help to do multi-threading

Can some one help me in creating an application that constantly polls the specified local directory for any new XML files. When an XML file is detected, it will create a new thread to handle the processing of the file, it will then assign the XML file to the new thread, and move the XML to temp directory.

despite the few information about your program, the usage of timers seems be the best choice:
import java.util.*;
public class MainAppClass
     MainAppClass()
          Timer dirCheck = new Timer();
          long CHECKING_INTERVAL = 20000; // milliseconds
          // you may also include parameters in the TimerTask extended class
          // like the list of directories, etc.
          DirListener dirListener = new DirListener();
          // Now you schedule the TimerTask execution
          dirCheck.schedule(dirListener, 0, CHECKING_INTERVAL);
class DirListener extends TimerTask
     public void run()
          // here you verify the list of directories
          // and launch one thread for each XML file
          // founded in these directories
}take a look in the java.util.Timer and java.util.TimerTask classes

Similar Messages

  • Help with understanding multi-threaded code

    Hi Everyone,
    I am currently reading a book on multi-threading and up until recently I have been able to understand what is going on. The thing is the complexity of the code has just jumped up about two gears without warning. The code is now using inner classes which I am trying to develop an understanding of but I am not finding it easy going, and the book has been lite on explanations. If anybody can help with the following code it will be really appreciated.
    public class SetPriority extends Object
         private static Runnable makeRunnable()
              Runnable r = new Runnable()
                   public void run()
                        for(int i=0; i<5; i++)
                             Thread t = Thread.currentThread();
                             System.out.println("in run() - priority=" + t.getPriority() +
                                          ", name=" + t.getName());
                             try{
                                  Thread.sleep(2000);
                             }catch(InterruptedException x){
                                  //ignore
              return r;
         public static void main(String[] args)
              Thread threadA = new Thread(makeRunnable(), "threadA");
              threadA.setPriority(8);
              threadA.start();
              Thread threadB = new Thread(makeRunnable(), "threadB");
              threadB.setPriority(2);
              threadB.start();
              Runnable r = new Runnable()
                   public void run()
                        Thread threadC = new Thread(makeRunnable(), "threadC");
                        threadC.start();
              Thread threadD = new Thread(r, "threadD");
              threadD.setPriority(7);
              threadD.start();
              try{
                   Thread.sleep(3000);
              }catch(InterruptedException x){
                   //ignore
              threadA.setPriority(3);
              System.out.println("in main() - threadA.getPriority()=" + threadA.getPriority());
    }My greatest challenge is understanding how the makeRunnable() method works. I don't understand how this inner class can be declared static and then multiple "instances" created from it. I know that I have no idea what is going on, please help!!!
    Thanks for your time.
    Regards
    Davo
    P.S.: If you know of any really good references on inner classes, particularly URL resources, please let me know. Thanks again.

    Yikes!! The good news is that you're unlikely to see such convoluted code in real life. But here we go.
    "private static Runnable makeRunnable()" declares a method that returns objects of type Runnable. The fact that the method is declared "static" is pretty irrelevant - I'll describe what that means later.
    The body of the method creates and returns an object of type Runnable. Not much special about it, except that you can give such an object to the constructor of class Thread and as a result the run() method of this Runnable object will be called on a new thread of execution (think - in parallel).
    Now the way it creates this Runnable object is by using the "anonymous inner class" syntax. In effect the method is doing the same as
    public class MyNewClass implements Runnable {
        public void run() {
            // All the same code inside run()
    public class SetPriority {
        private static Runnable makeRunnable() {
            Runnable r = new MyNewClass();
            return r;
        // The rest of the original code
    }Except you don't bother declaring MyNewClass. You're not interested in defining any new method signatures. You just want to create an object that implements Runnable and has certain instructions that you want inside the run() method. Think of the whole approach as shorthand.
    Think about this for a while. In the mean time I'll write up the "static".

  • Helpful hint while multi-threading

    Hi all
    This had me stupmed for a little while. A multi-threaded program I'd been working didn't appear to be working correctly. I noticed this was because it looked like the thread never made it to its run() method. The cause of this was the fact id overridden the start() method of the thread without including this.run() at the end. The symptoms of this happening aren't obvious though, and it can be quite puzzling. I hope this gets added to any FAQs etc, or solves someones problem.

    And if, for whatever reason, you do need to override start(), you should not call this.run() at the end, you should call super.start() !!!
    If you call this.run() at the end, you are having the current thread go and do the run method.

  • Need Help Creating A Multi-Colored Background Image??

    I'm trying to create a random multi-colored 200 x 200 image that will be used for a tiled background.  The attached sample image will illustrated the random effect that I'm trying to acheive just using different colors though.  Say if I wanted to use (blue, gold, white and light blue), is there a tool or option in Photoshop that will let me select the multiple colors then automatically generate that random pattern or one similar to it???  Or , is this something that I will have to do on multiple layers using filters, etc. then merge them all together??
    Any help will be appreciated.
    ET

    I think I've come up with something pretty close enough using a combination of Filters (Clouds, Brush Strokes and Noise) once I selected a foreground/background color combination.
    Thanks,
    ET

  • Need help with creating multi out instruments...

    What do I do wrong here… I tried to figure this out already since at least 1 year. I am desperate!
    Here is what I do while trying to make a multi output instrument in logic studio 9:
    1:I create 1 software instrument:
    2: I choose a multi output stereo AU Instrument:
    3: I load 5 software instruments, each on its own channel, all in the same Logic Instrument:
    4: In the mixer,  I created 5 Aux channels by clicking on the + sign of the Instrument:
    5: In the arrange window, I  create 5 new channels from the Track menu with New with Next Midi Channel:
    Now when playing  the 1st instrument track, still the sound goes directly to the output 1/2, the Aux sliders don't have any control over the volume. What do I do wrong?
    Hope to find some help,
    André

    Hi
    Depending on which version of Kontakt you are using, there are some "automated" ways of creating additional outputs, and assigning each sound to a different output:
    Pic show Kontakt 4
    Once you have done that, and (in Logic) loaded a Multi-Out instance of Kontakt, all you have to do is create the additional Aux channels in the mixer (using the small +) at the bottom of the Instrument Channel Strip).
    CCT

  • Need help with HD Multi-cam editing...

    So it is my understanding that you can't view a multi-cam sequence unless the footage you are viewing is unrendered/unlimited...
    So my question is... how do I take rendered footage and de-render it so its unlimited... I tried adding an effect but even color corrector just makes the footage go from rendered to "needs render" which is no good.
    For those who understand multi-cam editing better... could you provide some pointers. Thanks!

    nvm i figured it out.

  • Need help with Exception in thread "main" java.lang.NullPointerException

    here is the error
    Exception in thread "main" java.lang.NullPointerException
    at stream.createFrame(stream.java:153)
    at chat.createMessage(chat.java:14)
    this is where the error is in stream
    public void createFrame(int id) {
              *buffer[currentOffset++] = (byte)(id + packetEncryption.getNextKey());*
    and this is where it comes from in chat
    outStream.createFrame(85);                    
    i just cant see whats causeing the exception

    spiderjava wrote:
    the variable state is assigned to test1. This variable(test1) is not initialized anywhere.It is initialized in the c'tor. Which is invoked after the "global" object and attribute initialization. So it is there, but comes too late.
    You should definitly not write a technical Java blog and post it all over the place.

  • Beginner needs help making a multi-color sphere!

    Hello all,
    I am an Illustrator CS3 newbie and I have run into a hurdle. I am trying to make a blue sphere with ONE gray quadrant. That is, 3/4 of the sphere looks blue, but the upper right 1/4 looks gray.
    I can make a fine looking blue sphere by placing a small light blue circle inside a larger dark blue circle, and doing a Blend. I tried to place a gray rectangle over that blended sphere and do a Pathfinder Divide, but the blended sphere doesn't want to accept my Divide.
    When I try doing the Pathfinder Divide first, I get a 2D circle with the right color scheme (3/4 blue and 1/4 gray) but when I go to blend a smaller circle into that to attempt to make a 3D sphere effect, it goes all screwy.
    Help me, Illustrator veterans! What is the right way to make a blue sphere with a gray quadrant???

    1. Turn on Smart Guides.
    2. Ellipse Tool: Shift Drag to draw a circle.
    3. Attributes Palette: Turn on the Show Center icon.
    4. Deselect.
    5. White Pointer: Select the upper right segment of the circle. Click the segment, not an anchorPoint. Edit>Cut. Edit>PasteInFront. You now have two paths.
    6. Pen Tool: Click the upper anchorPoint of the single-segment path you just pasted. Move the Pen cursor downward until SmartGuides senses the center. Click. Move the Pen cursor rightward and click the other endpoint of the path. The path is closed. You now have two paths: one open, one closed. Select both paths.
    7. Gradient Palette: Click the Gradient icon. Set it to Radial. Each of the two paths now has a gray radial grad fill. Leave both paths selected.
    8. Gradient Tool: Mousedown in the midde of the smaller path, drag diagonally leftward and downward, crossing the center and a little beyond. The figure should look fairly like a sphere, with the highlight in the upper right. It appears that one continuous Grad Fill spans both objects, but in fact, each still has its own fill. Deselect. Select the larger path (the part you want to be blue).
    9. Gradient Palette: Edit the colors of the two color stops, making the white one light blue and the black one dark blue.
    10. Set stroke to None on both paths.
    JET

  • LabVIEW built DLL's in a multi-threaded C++ app, Help Needed!

    I'm working on a software application that is being developed
    primarily in C++. There is a component of this larger application,
    however, that is being developed in LabVIEW (for several reasons that
    I won't dive into here). This LabVIEW code is therefore executed
    within a C++ wrapper class that calls a LabVIEW built DLL.
    All this was fine and dandy, untill we decided to multi-thread our C++
    application. As a result, the LabVIEW DLL now gets called from
    multiple threads simultaneously. From all of my testing, it appears
    that resource locking is occuring such that only one thread has access
    to the .dll at a time. If I make the .vi used to define the dll
    function prototype as non-reentrant then this is what we see. As an
    example, say we have 3 threads all calling the same .dll method call.
    Thread 1, 2, and 3 all call the .dll within a few milliseconds of each
    other. Thread 1 completes the .dll call after X milliseconds. Thread 2
    completes the .dll call after 2X milliseconds, and thread 3 completes
    after 3x milliseconds.
    Now, changing the vi to reentrant, and running the same test, we see
    Thread 1, 2, and 3 all complete the .dll call in 3x milliseconds.
    While the fact that they now take the same amount of time to complete
    would lead you to believe they are happening in parallel, the fact
    that it takes 3x milliseconds as opposed to X milliseconds means they
    are not.
    Has anyone ever dealt with these issues before? Is it possible that
    messing with the "execution system" for the vi will have an affect?
    What if different .dll methods but still attached to the same .dll are
    called from different threads? Same behavior? Is it a lost cause? Is
    there no way to make code within a single LabVIEW built .dll run in
    two different threads at the same? From what I understand this is
    easily doable with a normal (non-LV built) .dll.
    Please, if anyone has any advice in this area, let me know!!!
    Much appreciated,
    Jesse Hurdus

    Duplicate post.

  • Need help with threads?.. please check my approach!!

    Hello frnds,
    I am trying to write a program.. who monitors my external tool.. please check my way of doing it.. as whenever i write programs having thread.. i end up goosy.. :(
    first let me tell.. what I want from program.. I have to start an external tool.. on separate thread.. (as it takes some time).. then it takes some arguments(3 arguments).. from file.. so i read the file.. and have to run tool.. continously.. until there are arguments left.. in file.. or.. user has stopped it by pressing STOP button..
    I have to put a marker in file too.. so that.. if program started again.. file is read from marker postion.. !!
    Hope I make clear.. what am trying to do!!
    My approach is like..
    1. Have two buttons.. START and STOP on Frame..
    START--> pressed
    2. check marker("$" sign.. placed in beginning of file during start).. on file..
         read File from marker.. got 3 arg.. pass it to tool.. and run it.. (on separate thread).. put marker.. (for next reading)
         Step 2.. continously..
    3. STOP--> pressed
         until last thread.. stops.. keep running the tool.. and when last thread stops.. stop reading any more arguments..
    Question is:
    1. Should i read file again and again.. ?.. or read it once after "$" sign.. store data in array.. and once stopped pressed.. read file again.. and put marker ("$" sign) at last read line..
    2. how should i know when my thread has stopped.. so I start tool again??.. am totally confused.. !!
    please modify my approach.. if u find anything odd..
    Thanks a lot in advance
    gervini

    Hello,
    I have no experience with threads or with having more than run "program" in a single java file. All my java files have the same structure. This master.java looks something like this:
    ---master.java---------------------------------------------------
    import java.sql.*;
    import...
    public class Master {
    public static void main(String args []) throws SQLException, IOException {
    //create connection pool here
    while (true) { // start loop here (each loop takes about five minutes)
    // set values of variables
    // select a slave process to run (from a list of slave programs)
    execute selected slave program
    // check for loop exit value
    } // end while loop
    System.out.println("Program Complete");
    } catch (Exception e) {
    System.out.println("Error: " + e);
    } finally {
    if (rSet1 != null)
    try { rSet1.close(); } catch( SQLException ignore ) { /* ignored */ }
    connection.close();
    -------end master.java--------------------------------------------------------
    This master.java program will run continuously for days or weeks, each time through the loop starting another slave process which runs for five minutes to up to an hour, which means there may be ten to twenty of these slave processes running simultaneously.
    I believe threads is the best way to do this, but I don't know where to locate these slave programs: either inside the master.java program or separate slave.java files? I will need help with either method.
    Your help is greatly appreciated. Thank you.
    Logan

  • Need help on Multi level menu implementation

    Hi All,
    Need help on Multi level menu implementation
    Thanks,
    Anu

    Hi Anu,
    Please go through this link Implement Multilevelmenu navigation
    Thanks,

  • Need help  regarding Daemon threads

    Hi to All
    What are deamon threrads ?
    Why we need to set Deamon(true)?
    explain me clearly
    I know deamon threads are low prior
    Again why we need to set to true.
    Help me

    You have two threads running. Neither one is daemon. One ends. The other keeps on running.
    You have two threads running. One is daemon. The daemon thread ends. The other keeps on running.
    You have two threads running. One is daemon. The other thread ends. The application ends because the only remaining thread is a daemon.
    You have five threads running. Three are daemon. A non-daemon thread ends. All other threads keep on running. A daemon thread ends. All other threads keep on running. The only remaining non-daemon thread ends. The application ends because the only remaining threads are daemons.
    Got it?

  • HELP!....GUI crashes when i call a multi-threaded program from it

    Hi..I have encountered a problem in my end of year project, which i cant see to solve. The problem is i am starting a multi-threaded program for a JButton on a GUI. All though this starts the other program it crashes the GUI completely how do i stop this.
    this is the code i use to call the threaded program.
    public void actionPerformed(ActionEvent e)
    Object target=e.getSource();
    String line = new String();
    if( target==b1 )
         try
    cl = new client();
         cl.startup();
         catch(Exception ex){ex.printStackTrace();}
    thanks Mike

    No there is no exceptions being given. this is one of the reasons why i dont no what to do. i thought myself that the threaded was taking all the resources and not going back to the GUI. if this is the case is there anyway that i can call back the GUI and keep the threaded program running?
    thanks
    mike.

  • Multi-Threaded FTP

    Multi-Threaded FTP was a huge attraction for me, and one of the features that sold me on upgrading to Dreamweaver CS6.  However, I haven't seen any sign of it in the product or any documentation to help me use it.  My files keep transferring in the traditional one-at-a-time way.
    Is there something I need to do to enable this feature? Has anybody used this feature yet?

    Might not help but I saw this in the comments on David Powers' blog
    http://foundationphp.com/blog/2012/04/23/my-verdict-on-dreamweaver-cs6/
    "Multi-thread FTP is the default in Dreamweaver CS6. You can neither turn it on nor off. It handles a maximum of three transfers simultaneously in either direction (so you can download at the same time as uploading). However, it doesn’t work with Check In/Check Out."
    He also has the following comments in the body of the blog entry:
    Multichannel FTP
    Let’s be honest. In the past, Dreamweaver’s FTP client was a dog. Not any more. It now supports multichannel transfers, and can even download at the same time as uploading. Orange arrows indicate items queued for transfer. When the transfer begins, the arrow turns green. And if you’re transferring a large item, hovering over the filename displays a tooltip of how much of the file has been transferred. With Dreamweaver CS5.5, it took more than 90 minutes to  upload a WordPress site on my internet connection. Now, it’s more than ten times faster.
    The FTP error messages are also more meaningful. No one is likely to buy Dreamweaver CS6 for its FTP client alone, but this is a major improvement to the program.

  • Multi-thread failure - Error in assignment

    Hello
    I have a c++ program processor running under Windows XP with Oracle 9i. My program access to oracle by an ODBC driver version 9.2.0.4.0. It could be launched in multi-thread to increase performance. When I launch it with one thread everything is fine. When I use several threads I have problems. ODBC driver returns to me a "error in assignment ... General error" message and my updates queries failed. Under SQl server it works without problems. It seems to be a kind of deadlock. When I disable check box in my odbc driver of "enable query timeout" my program encounter a problem and freezes...
    Could someone help me ?

    user13335017 wrote:
    I have thought of the above solutions as workable, however, it is not. Some exhibited errors are:
    A. "Attempt to use database while environment is closed." This error applies to 2, 3 and 4 all the way;
    B. "Attempt to read / write database while database is closed." This error applies to 3 in particular;
    C. "Attempt to close environment while some database is still open." This error applies to 5.
    Please help me with designing a better strategy to solve the concurrent issue. Many thanks in advance.All these are expected errors. You should design the application so that you do not close an environment handle while database handles are still open, keep database handles open for as long as operations need to be performed on the underlying databases, open the database handles after opening the database handles, and close database handles before closing the environment handle.
    In short, in pseudo-code, you should have something like this:
    - open environment handle,
    - open database handles,
    - perform whatever operations are needed on the databases,
    - close database handles,
    - close environment handle.
    You can refer to the Getting Started with Data Storage and the Getting Started with Transaction Processing guides appropriate for the API you are using, from the Berkeley DB documentation page.
    Regards,
    Andrei

Maybe you are looking for

  • No track list shown

    Hi, I have a problem with iTunes. I started it some minutes ago in order to search for a song. But the results of my search were not shown in the usual way. Usually there is a window on the top and a long list with all songs found among this window.

  • In app purchasing disabled

    Trying to might make a purchase of coins and getting the message            "in app purchasing disabled" Went to Settings ... Apple ID ... payment information ... and it's all correct in there .. I updated it .. I don't know why it always asks for my

  • Format first and last record of result query

    Hello I have the following query <tt>select 1 seq, 'This is First record' data from dual union all select 2, 'Data ' || tname from tab union all select 3, 'This was last record Last record' from dual order by 1</tt> When i spool this statement to a l

  • Generating html from word processing document

    I've got a fairly short two-column newsletter with six graphics that I want to publish in html using AW v6.2. I select save as html but the resulting document includes none of my text or graphics, hmmm. So I look at the web templates starting points

  • Pop up in module pool

    Hi forum, My requirement is whenever i change entry which is greater than 1000 in table control i should get a pop up message 'wrong entry'. Pls help me. its very urgent... regards mallika