vavkkishore
Programmer
Hi Java gurus,
I have a question and facing that problem now.
I working on an application where I have to read say 1000 (approximate value, may be less or more than this value in future), files where each file contains areound 3000 lines. User will give me folder name from where I have to read the files in that folder and their contents. We want it in a a multithreaded approach. I know all the file names in that folder. After knowing the file names, I wrote a thread class which will take the file name and read the contents of the file. I set maximum threads as say 10. So 10 threads are reading 10 files each containing around 3000 lines. I have a threadmanager for this, which will create the above threads. I also had a StringBuffer object in ThreadManager class which is a global one to all the threads. Once a thread completes its reading of file, it will call setFileContents method in the threadmanager, which will add that string to the global StrinbBuffer object and this method is synchronized one.
Problem is, when there are say 100 files, each file having 3000 lines, then this StringBuffer is coming out of the application because of OutofMemoryException.
Once I get the contents of all the files, ThreadManager will write it to an AWT component showing the contents of all the files.
My question is, how to come out of that problem, I change the heap size also at java command options, secondly what are the best approaches for this multithread application, so that the contents of all the files will come in an order of the file names and those contents are shown in the AWT component.
I want it urgently and I will be thankful for that.
Thanks in advance for your advices.
I have a question and facing that problem now.
I working on an application where I have to read say 1000 (approximate value, may be less or more than this value in future), files where each file contains areound 3000 lines. User will give me folder name from where I have to read the files in that folder and their contents. We want it in a a multithreaded approach. I know all the file names in that folder. After knowing the file names, I wrote a thread class which will take the file name and read the contents of the file. I set maximum threads as say 10. So 10 threads are reading 10 files each containing around 3000 lines. I have a threadmanager for this, which will create the above threads. I also had a StringBuffer object in ThreadManager class which is a global one to all the threads. Once a thread completes its reading of file, it will call setFileContents method in the threadmanager, which will add that string to the global StrinbBuffer object and this method is synchronized one.
Problem is, when there are say 100 files, each file having 3000 lines, then this StringBuffer is coming out of the application because of OutofMemoryException.
Once I get the contents of all the files, ThreadManager will write it to an AWT component showing the contents of all the files.
My question is, how to come out of that problem, I change the heap size also at java command options, secondly what are the best approaches for this multithread application, so that the contents of all the files will come in an order of the file names and those contents are shown in the AWT component.
I want it urgently and I will be thankful for that.
Thanks in advance for your advices.