Waiting until files are being created

Discussion in 'Java' started by Wesley Mesquita, Mar 4, 2008.

  1. Hi all,
    I am having a problem that in a software that I am developing there is
    some ammount of code that invokes console commands (using Runtime
    exec). These include directory creation, file compilation and so on.
    Following the software flow, most of time I need these created files
    immediatally after run Runtime exec and because the system delay they
    aren´t ready, so I have to wait until the files have been created. My
    poor solution has been an empty loop with a new File object and stay
    asking if the files exists (or even worse I thought to put a
    Thread.sleep(time)).

    My question is: Is there any better solution to deal with this?

    Thanks in advance.
     
    Wesley Mesquita, Mar 4, 2008
    #1
    1. Advertising

  2. Wesley Mesquita wrote:
    > Hi all,
    > I am having a problem that in a software that I am developing there is
    > some ammount of code that invokes console commands (using Runtime
    > exec). These include directory creation, file compilation and so on.
    > Following the software flow, most of time I need these created files
    > immediatally after run Runtime exec and because the system delay they
    > aren´t ready, so I have to wait until the files have been created. My
    > poor solution has been an empty loop with a new File object and stay
    > asking if the files exists (or even worse I thought to put a
    > Thread.sleep(time)).
    >
    > My question is: Is there any better solution to deal with this?
    >
    > Thanks in advance.


    Why don't you just create the files and directories in Java?

    --

    Knute Johnson
    email s/nospam/knute/

    --
    Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
    ------->>>>>>http://www.NewsDem
     
    Knute Johnson, Mar 4, 2008
    #2
    1. Advertising

  3. Wesley Mesquita

    Roedy Green Guest

    On Mon, 3 Mar 2008 17:54:13 -0800 (PST), Wesley Mesquita
    <> wrote, quoted or indirectly quoted someone
    who said :

    >My question is: Is there any better solution to deal with this?


    Yes. Don't use command scripts. Do it directly from Java. See
    http://mindprod.com/jgloss/file.html and
    http://mindprod.com/products1.html#BATIK for how.

    If you must use scripts, your code becomes platform dependent. But
    you can wait. See http://mindprod.com/jgloss/exec.html
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Mar 4, 2008
    #3
  4. On Mar 4, 12:21 am, Knute Johnson <>
    wrote:
    > Wesley Mesquita wrote:
    > > Hi all,
    > > I am having a problem that in a software that I am developing there is
    > > some ammount of code that invokes console commands (using Runtime
    > > exec). These include directory creation, file compilation and so on.
    > > Following the software flow, most of time I need these created files
    > > immediatally after run Runtime exec and because the system delay they
    > > aren´t ready, so I have to wait until the files have been created. My
    > > poor solution has been an empty loop with a new File object and stay
    > > asking if the files exists (or even worse I thought to put a
    > > Thread.sleep(time)).

    >
    > > My question is: Is there any better solution to deal with this?

    >
    > > Thanks in advance.

    >
    > Why don't you just create the files and directories in Java?
    >
    > --
    >
    > Knute Johnson
    > email s/nospam/knute/
    >
    > --
    > Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
    > ------->>>>>>http://www.NewsDem


    Directories I am creating using File (I made a mistake in first post),
    but I still have to compile some java sources. I´ll see the tips that
    Roedy gave (specially Batik), and soon I´ll post the results.

    Thanks
     
    Wesley Mesquita, Mar 4, 2008
    #4
  5. Wesley Mesquita, 04.03.2008 02:54:
    > My poor solution has been an empty loop with a new File object and stay
    > asking if the files exists (or even worse I thought to put a
    > Thread.sleep(time)).


    Thread.sleep() is a lot better than having an empty loop as it will release CPU cycles and will not waste CPU time in a loop which doesn't do anything.

    So if you need to call exec() and have to wait for it, by all means use Thread.sleep() while polling for the existence of the file.

    Thomas
     
    Thomas Kellerer, Mar 4, 2008
    #5
  6. On Mar 4, 7:56 am, Thomas Kellerer <> wrote:
    > Wesley Mesquita, 04.03.2008 02:54:
    >
    > > My poor solution has been an empty loop with a new File object and stay
    > > asking if the files exists (or even worse I thought to put a
    > > Thread.sleep(time)).

    >
    > Thread.sleep() is a lot better than having an empty loop as it will release CPU cycles and will not waste CPU time in a loop which doesn't do anything..
    >
    > So if you need to call exec() and have to wait for it, by all means use Thread.sleep() while polling for the existence of the file.
    >
    > Thomas


    I thought it is worse since I don´t how much time put it to sleep. For
    instance, if it needed 500ms and I put 2000ms I waste 1500ms.
     
    Wesley Mesquita, Mar 4, 2008
    #6
  7. Wesley Mesquita, 04.03.2008 12:16:
    > On Mar 4, 7:56 am, Thomas Kellerer <> wrote:
    >> Wesley Mesquita, 04.03.2008 02:54:
    >>
    >>> My poor solution has been an empty loop with a new File object and stay
    >>> asking if the files exists (or even worse I thought to put a
    >>> Thread.sleep(time)).

    >> Thread.sleep() is a lot better than having an empty loop as it will release CPU cycles and will not waste CPU time in a loop which doesn't do anything.
    >>
    >> So if you need to call exec() and have to wait for it, by all means use Thread.sleep() while polling for the existence of the file.
    >>
    >> Thomas

    >
    > I thought it is worse since I don´t how much time put it to sleep. For
    > instance, if it needed 500ms and I put 2000ms I waste 1500ms.


    It's still more efficient to use 500ms (or even 100ms) compared to not waiting at all.

    Thomas
     
    Thomas Kellerer, Mar 4, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ProJee
    Replies:
    0
    Views:
    858
    ProJee
    Jul 21, 2004
  2. Alessandro Giambruno

    Waiting until timer without cpu crash?

    Alessandro Giambruno, Jun 18, 2004, in forum: Java
    Replies:
    9
    Views:
    2,907
    Roedy Green
    Jun 22, 2004
  3. Replies:
    1
    Views:
    1,946
  4. focode
    Replies:
    2
    Views:
    540
    Tom Anderson
    Dec 27, 2009
  5. Replies:
    1
    Views:
    140
Loading...

Share This Page