473,461 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how can I stop my applet freezing?

hi I'm completely new in Java's world, I made an applet that download a video file from the server, but here is the thing, when the recording process gets started my applet just freeze (doesn't accept any kind of event, like click button, enable or disable components) and when it finish then the applet come back to a normal state.


here is the code :

Expand|Select|Wrap|Line Numbers
  1. public void startRecordingProcess(String file){
  2.  
  3.      try
  4.      {
  5.  
  6.         /*
  7.          * Get a connection to the URL and start up
  8.          * a buffered reader.
  9.          */
  10.         browseFolderBtn.setEnabled(false);
  11.         long startTime = System.currentTimeMillis();
  12.  
  13.         System.out.println("Connecting to the server\n");
  14.  
  15.         URL url = new URL("http://xserverX/hd/video.flv");
  16.         url.openConnection();
  17.         InputStream reader = url.openStream();
  18.  
  19.         /*
  20.          * Setup a buffered file writer to write
  21.          * out what we read from the website.
  22.          */
  23.  
  24.         FileOutputStream writer = new FileOutputStream(file);
  25.         byte[] buffer = new byte[153600];
  26.         int totalBytesRead = 0;
  27.         int bytesRead = 0;
  28.  
  29.         System.out.println("Recording video........\n");
  30.  
  31.         while ((bytesRead = reader.read(buffer)) > 0)
  32.         {
  33.            writer.write(buffer, 0, bytesRead);
  34.            buffer = new byte[153600];
  35.            totalBytesRead += bytesRead;
  36.         }
  37.  
  38.         long endTime = System.currentTimeMillis();
  39.  
  40.         System.out.println("Finish. " + (new Integer(totalBytesRead).toString()) + " bytes read (" + (new Long(endTime - startTime).toString()) + " millseconds).\n");
  41.         writer.close();
  42.         reader.close();
  43.         browseFolderBtn.setEnabled(true);
  44.      }
  45.      catch (MalformedURLException e)
  46.      {
  47.         e.printStackTrace();
  48.      }
  49.      catch (IOException e)
  50.      {
  51.         e.printStackTrace(); 
  52.      }
  53.     }
  54.  
  55.  
Aug 26 '10 #1
4 2148
Nepomuk
3,112 Expert 2GB
Hi there!

I'm no expert on applet writing, but I'm guessing you aren't using threads? That would certainly explain the freezing up of the applet when you start downloading. If you create a separate thread for the download, the applet should continue working.

Greetings,
Nepomuk
Aug 27 '10 #2
Dheeraj Joshi
1,123 Expert 1GB
What is the size of the video that you are trying to download? Is it too big?

Regards
Dheeraj Joshi
Aug 27 '10 #3
@Nepomuk right now im creating a thread for the download process, at the end of the day I hope this class helps me to download multiple video files at the same time. Thank you.

@Dheeraj Joshi actually the video size is dynamic but it could be between 500 mb to 4GB, does that make a difference?. Thank you.
Aug 27 '10 #4
Nepomuk
3,112 Expert 2GB
Yes, it could allow you to download several videos at a time. Or have it do something else at the same time. So, hope it works out. :-)

From what I can tell, the video size shouldn't normally cause anything like this - if anything it would fill up the RAM and therefore block the computer from doing much at all, but that would influence more than just the rest of the applet. 4GB could possibly do that, if it's not written to disk fast enough, but I think that from the way your program works that shouldn't be the problem.

Greetings,
Nepomuk
Aug 27 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: WMMorgan | last post by:
There's a website I like to visit that has an user-interactive java application. There's a "visual applet" component and "control applet" component. (No, it's not an adult or porno site.) But...
0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
2
by: Jonathan | last post by:
Hi I'm doing a project for school and wrote an applet that makes a socket connection to a server (smae host as webserver) that was setup for this project. In the applet there are 3 buttons and by...
2
by: Tom | last post by:
A Java applet has two methods stop() and destroy() that get called when the user moves to a different page. Does javascript have anything similar? thanks tom
11
by: Frank Rizzo | last post by:
Hello, My c# based windows service takes a while to dispose. I have to release bunch of resources all over the place and unfortunately it can take 20-40 seconds before I can cleanly exit. ...
0
by: Chris Dunaway | last post by:
I wish to write a small application that will allow me to start and stop a windows service on another server. Currently, I have to connect to the server using Remote Desktop Connection and then...
0
by: ankur | last post by:
WHEN I RUN THIS WEB APPLICATION ON Tomcat5.5.9 SERVER MY HttpChatApplet sccessfully Loaded from ChatDispatch but running on some another PC HttpChatApplet not loaded my Coad ...
8
by: Richard Maher | last post by:
Hi, I am in a mouseup event for button A and I'd like to disable=false button B before starting some work. Is there anyway that an event for button B can then fire before my event processing for...
1
by: sheephead86 | last post by:
Hi, I'm pretty new to java, and I have a small problem involving drawing a rectangle on a java applet.Firstly this is not a plea for someone to help me with this peice of work, I just need pointing...
2
by: ManidipSengupta | last post by:
Hi, a few (3) questions for the Java experts, and let me know if this is the right forum. It deals with 100% java code (reason for posting here) but manages a Web browser with Javascript. Thanks in...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.