Avatar billede fredand Forsker
14. december 2005 - 21:21 Der er 4 kommentarer og
1 løsning

How to waite for a file to be written in a godd way?

Hello!

I wonder if any one got a good solution for this problem.

I got a servlet that boundles a couple of files and stores them into a zip-file.

When the zip-file is written to disk the servlet should display a link to the zip-file so the user is able to download it.

But my servlet is in a bit of a hurry, it displays the link before the zip-file exists.

So if any one could give a good solution for this it would be great.

Correct me if I'm wrong when I say that this looks bad:

//write the zip file

while(!zipFile.exits())
{
}

//Display the response

Best regards
Fredrik
Avatar billede arne_v Ekspert
14. december 2005 - 21:31 #1
without sleep witing the while loop : disaster

with sleep in while loop : not elegant but
Avatar billede fredand Forsker
14. december 2005 - 21:38 #2
Hello!

Do you mean like this:

while(!zipFile.exits())
{
Thread.sleep(100);
}

I guess you would prefer some FileManager running in a own thread and that we should use wait and notify instead?

Or do you got some other thoughts about this?

Fredrik
Avatar billede arne_v Ekspert
14. december 2005 - 21:42 #3
yes

no

more like immediatetly creating a link to a download servlet which
serves the file if it exist ir else just say "not ready yet + try again
in N seconds"
Avatar billede fredand Forsker
15. december 2005 - 13:00 #4
Hello!

That sound like a great design!!

Thanks!

Please give a svar!

Best regards
Fredrik
Avatar billede arne_v Ekspert
15. december 2005 - 14:27 #5
ok
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester