Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

application "freezing"

 
Agapios Hartzoulakis
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, here is my problem.
I'va made an application which reads a big amount of .txt files. This task takes a few minutes. The problem is that until this task is accomplished the application tottaly "freezes". Is there a way to avoid it?

The code goes like this:



Thanks in advance.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One possible solution is, to use a seperate thread that will take care of reading a file and do necessary tasks. The application is freezing because the same thread is used to control the GUI (or APP )and reads a big file.

HTH
 
Agapios Hartzoulakis
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you give me a simple example of this?
Thanks
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you can do is create a new thread. In the run method of the thread read this big file.



If you need the contents of this file create an instance of Thread class with myFileReader's object, and run this thread.

If you need to know more on threads chect it here
 
Agapios Hartzoulakis
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot. I could not expect anything more useful.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic