Results 1 to 4 of 4
Thread: Help with "implements Runnable"
- 10-08-2013, 06:09 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 23
- Rep Power
- 0
Help with "implements Runnable"
I am pretty new to Java and the more I read about threads, the more I start to get confused. I have a method that does a database task that can sometimes take awhile. When it does this my GUI locks up until the task is done. So I figured running this on a separate thread would make sense.
Here is what I have in my class
Java Code:public class BucketTool implements Runnable{ private String bucketPath; private String user; private String pass; private String dbset; private String dbname; private String qr; public void bucket(String bucketPath, String user, String pass, String dbset, String dbname, String qr) { this.bucketPath = bucketPath; this.user = user; this.pass = pass; this.dbset = dbset; this.dbname = dbname; this.qr = qr; public void bucket(String bucketPath, String user, String pass, String dbset, String dbname, String qr) { .....some method logic here } @Override public void run(){ bucket(bucketPath, user, pass, dbset,dbname,qr); } }
Java Code:// if(fail ==0){ // BucketTool BucketT = new BucketTool(); // BucketT.bucket(bucketPath, user, pass, dbset, dbname, qr); // } if(fail ==0){ BucketTool BucketT = new BucketTool(); Thread t = new Thread(BucketT); t.start(); }
Thanks.
- 10-08-2013, 06:14 PM #2
Re: Help with "implements Runnable"
It looks like you would pass it into a constructor for BucketTool.
How to Ask Questions the Smart Way
Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum - Come say hello!
- 10-08-2013, 06:49 PM #3
Member
- Join Date
- Feb 2012
- Posts
- 23
- Rep Power
- 0
Re: Help with "implements Runnable"
That worked! Thanks.
- 10-09-2013, 11:06 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: Help with "implements Runnable"
If your GUI is a Swing GUI then it has the SwingWorker whose job it is to launch background tasks like this.
That is assuming this is a task that is launched by the user interacting with the GUI.Please do not ask for code as refusal often offends.
** This space for rent **
Similar Threads
-
access denied("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")
By klspepper in forum New To JavaReplies: 0Last Post: 12-07-2012, 09:29 AM -
Convert string operation symbols "+", "-", "/", "*" etc.
By Googol in forum New To JavaReplies: 3Last Post: 10-30-2012, 04:06 PM -
"extends" and "implements"
By newbie101 in forum New To JavaReplies: 6Last Post: 02-27-2012, 03:12 PM -
"implements from Runnable"
By newbie101 in forum New To JavaReplies: 1Last Post: 08-04-2011, 07:18 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 08:35 AM
Bookmarks