Results 1 to 5 of 5
Thread: My thread will not start
- 03-28-2008, 04:12 PM #1
Member
- Join Date
- Mar 2008
- Posts
- 3
- Rep Power
- 0
My thread will not start
I have my thread class (which transmits a datagram):
and then the following two lines in my main program.Java Code:public class heartbeat extends Thread { private int portNum; private InetAddress address; private int siteNum; public heartbeat(InetAddress pAddress, int pPortNum, int pSiteNum) { portNum = 3001; address = pAddress; siteNum = pSiteNum; } public void Run() { byte[] buf = new byte[256]; String stringToSend = "[H," + siteNum + "]"; buf = stringToSend.getBytes(); System.out.println("Port is " + portNum); try { DatagramSocket socket = new DatagramSocket(portNum); DatagramPacket packet = new DatagramPacket(buf, buf.length, address, portNum); while(true) { System.out.println(stringToSend); socket.send(packet); } } catch (Exception e) { System.exit(0); } } }
It all looks right to me but the thread will not run and I can't see whats wrong with it!! Please help.Java Code:heartbeat myHeartbeat = new heartbeat(serverAddr, serverPort, siteID); myHeartbeat.start();
- 04-05-2008, 02:59 AM #2
Member
- Join Date
- Mar 2008
- Posts
- 1
- Rep Power
- 0
Capitalization.
public void run() overrides the run method
public void Run() makes a new method that doesn't override it.
- 10-03-2008, 12:42 PM #3
Member
- Join Date
- Oct 2008
- Posts
- 24
- Rep Power
- 0
change your Run into run() instead
- 10-03-2008, 02:22 PM #4
In the future use the @Override statement before methods that are overrides. The compiler will then tell you if your method is NOT overriding anything.
- 10-03-2008, 06:32 PM #5
Member
- Join Date
- Oct 2008
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
data from the main/GUI thread to another runnin thread...
By cornercuttin in forum Threads and SynchronizationReplies: 2Last Post: 04-23-2008, 10:30 PM -
If JNI thread call the java object in another thread, it will crash.
By skaterxu in forum Advanced JavaReplies: 0Last Post: 01-28-2008, 07:02 AM -
OutOfMemoryError: Unable to Start New Native Thread
By edwin11 in forum Advanced JavaReplies: 0Last Post: 11-16-2007, 01:47 PM -
How to start
By cachi in forum Java AppletsReplies: 1Last Post: 08-06-2007, 08:43 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks