Results 1 to 2 of 2
  1. #1
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default [SOLVED] New to Threads...

    I want to use threads to increase the speed of my program and I am not really sure if this is good practice and if this will cause any errors... I connect to a database and I have to do 5 queries and change one value in 4 arrays per query... I do one right away and it fills a JTable with data... The rest I want to run in the background... This is what I came up with:

    Java Code:
        public void doQuery(){
            
            new Thread(new Runnable(){
    
                public void run() {
                    
                    
                    //Query the database and update values in Arrays...
                    
                    //throw new UnsupportedOperationException("Not supported yet.");
                }
               
                
                
            }).start();
            
            
            
        }
    Within my program this has the potential to be called 50-100 times a day...

    Is this a good way to utilize threads?
    Who Cares... As Long As It Works...

  2. #2
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    After much research, This is not a suggested way to utilize threads...

    I believe Thread Pools are the answer... So if anybody has any helpful tutorials it will be greatly appreciated...
    Last edited by markw8500; 04-24-2009 at 03:00 AM.
    Who Cares... As Long As It Works...

Similar Threads

  1. Threads!
    By rameshraj in forum Advanced Java
    Replies: 1
    Last Post: 05-04-2008, 05:11 PM
  2. Using threads
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-11-2007, 11:25 AM
  3. Threads
    By one198 in forum Threads and Synchronization
    Replies: 1
    Last Post: 11-20-2007, 07:15 PM

Posting Permissions

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