Results 1 to 5 of 5
  1. #1
    markyoung1984 is offline Member
    Join Date
    Mar 2008
    Posts
    3
    Rep Power
    0

    Angry My thread will not start

    I have my thread class (which transmits a datagram):

    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); }
    
    	}
    
    }
    and then the following two lines in my main program.

    Java Code:
    	  	 heartbeat myHeartbeat = new heartbeat(serverAddr, serverPort, siteID);
    	  	 myHeartbeat.start();
    It all looks right to me but the thread will not run and I can't see whats wrong with it!! Please help.

  2. #2
    CJG
    CJG is offline Member
    Join Date
    Mar 2008
    Posts
    1
    Rep Power
    0

    Default

    Capitalization.

    public void run() overrides the run method

    public void Run() makes a new method that doesn't override it.

  3. #3
    kellaw is offline Member
    Join Date
    Oct 2008
    Posts
    24
    Rep Power
    0

    Default

    change your Run into run() instead

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default

    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.

  5. #5
    spider is offline Member
    Join Date
    Oct 2008
    Posts
    5
    Rep Power
    0

Similar Threads

  1. data from the main/GUI thread to another runnin thread...
    By cornercuttin in forum Threads and Synchronization
    Replies: 2
    Last Post: 04-23-2008, 10:30 PM
  2. Replies: 0
    Last Post: 01-28-2008, 07:02 AM
  3. OutOfMemoryError: Unable to Start New Native Thread
    By edwin11 in forum Advanced Java
    Replies: 0
    Last Post: 11-16-2007, 01:47 PM
  4. How to start
    By cachi in forum Java Applets
    Replies: 1
    Last Post: 08-06-2007, 08:43 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
  •