Results 1 to 5 of 5

Thread: multi thread

  1. #1
    rockzero is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Default multi thread

    i have no idea about how to create multi-thread to read different files.


    Uploaded with ImageShack.us

    i just can read the .dat to find the max no.
    here is my code


    Java Code:
    import java.io.*;
    
    public class Max extends Thread 
    {
      public Max(){
      
      }
        
        
      synchronized public void run(){
      int max = Integer.MIN_VALUE;
       try{      
            
            FileInputStream fis = new FileInputStream("C:/Documents and Settings/him/file2.dat");  
            DataInputStream dis = new DataInputStream(fis);
            
             while(dis.readInt()!= -1){
              
             int x = dis.readInt();
             if(x > max)  max = x;
             
             }          
       }
        catch (IOException e ){
         System.out.println(e);
    }
       finally{
           
           System.out.println(max);
           fis.close();
       }
    
        public static void main ( String[] args ) {
        Max a = new Max();
        a.start();
     } 
       
       
     }
    Last edited by rockzero; 12-10-2012 at 01:01 PM.

  2. #2
    rockzero is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Default Re: multi thread

    Is it necessary use db?
    It just a java homework.
    can someone give me some hints??

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: multi thread

    No it's not necessary to use a database but rather just some simple code will do.

    As for helping, your posted code is not very readable. Please read the links that Darryl has given you so you can correct this problem.

  4. #4
    rockzero is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Default Re: multi thread

    I have fixed my code.
    I just know how to find out the max no. in the .dat file by creating a instance.
    I dun know how to create three different threads to read each of the file .
    How can i do to match the requirement above.

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: multi thread

    Well for starters, you're hard coding your input in a single thread. That'll never work. Why not start with getting the list of input files working first?

Similar Threads

  1. Block thread until callback method has been called by other thread
    By James2000 in forum Threads and Synchronization
    Replies: 4
    Last Post: 05-11-2012, 10:46 PM
  2. Main Thread not waiting for grand child thread to finish
    By prashanthn in forum Threads and Synchronization
    Replies: 3
    Last Post: 06-07-2011, 10:26 AM
  3. Multi-Panel multi-class GUI communication
    By manji51 in forum AWT / Swing
    Replies: 4
    Last Post: 05-25-2011, 02:54 PM
  4. How come multi thread don't look like it?
    By jkhoa in forum Threads and Synchronization
    Replies: 1
    Last Post: 09-22-2007, 05:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •