multithreading - Java - File Download makes Program Stop -


when download file in java following code, can't use program anymore, it's not responding. when download finishs can use again.

url website = new url("my_url"); readablebytechannel rbc = channels.newchannel(website.openstream()); fileoutputstream fos = new fileoutputstream("grafik"); fos.getchannel().transferfrom(rbc, 0, long.max_value); 

how fix that? e.g. loading screen showed or dialog pops up? in advance :d

time learn wonderful world of concurrency!

new thread(new runnable() {     @override     public void run() {         url website = new url("my_url");         readablebytechannel rbc = channels.newchannel(website.openstream());         fileoutputstream fos = new fileoutputstream("grafik");         fos.getchannel().transferfrom(rbc, 0, long.max_value);     } }).start(); 

doing launch separate thread -- line of execution hat acts independently of 1 it's spawned from. allow user interface continue function while activity happens separately.

concurrency can tricky, though, once start wanting different threads interact. take @ oracle tutorial linked in post.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -