Waiting until files are being created

  • Thread starter Wesley Mesquita
  • Start date
W

Wesley Mesquita

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.
 
K

Knute Johnson

Wesley said:
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?
 
W

Wesley Mesquita

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

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
 
T

Thomas Kellerer

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
 
W

Wesley Mesquita

Wesley Mesquita, 04.03.2008 02:54:


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.
 
T

Thomas Kellerer

Wesley Mesquita, 04.03.2008 12:16:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top