Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Waiting until files are being created

Reply
Thread Tools

Waiting until files are being created

 
 
Wesley Mesquita
Guest
Posts: n/a
 
      03-04-2008
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.
 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      03-04-2008
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
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      03-04-2008
On Mon, 3 Mar 2008 17:54:13 -0800 (PST), Wesley Mesquita
<(E-Mail Removed)> 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
 
Reply With Quote
 
Wesley Mesquita
Guest
Posts: n/a
 
      03-04-2008
On Mar 4, 12:21 am, Knute Johnson <(E-Mail Removed)>
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
 
Reply With Quote
 
Thomas Kellerer
Guest
Posts: n/a
 
      03-04-2008
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
 
Reply With Quote
 
Wesley Mesquita
Guest
Posts: n/a
 
      03-04-2008
On Mar 4, 7:56 am, Thomas Kellerer <(E-Mail Removed)> 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.
 
Reply With Quote
 
Thomas Kellerer
Guest
Posts: n/a
 
      03-04-2008
Wesley Mesquita, 04.03.2008 12:16:
> On Mar 4, 7:56 am, Thomas Kellerer <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
waiting threads until it gets value focode Java 2 12-27-2009 06:19 PM
Update image immediately? How to avoid waiting until onload() finishes? stahl.karl@gmail.com Javascript 1 02-10-2006 07:37 AM
waiting until JFrame is closed deej21@gmail.com Java 1 04-04-2005 10:18 AM
How to force Response.WriteFile waiting until a file is downloaded? ProJee ASP .Net 0 07-21-2004 05:39 PM
Waiting until timer without cpu crash? Alessandro Giambruno Java 9 06-22-2004 09:44 PM



Advertisments