Hack Forums
[Java] parallel processing thread - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] parallel processing thread (/showthread.php?tid=5956472)



parallel processing thread - blackcoder00 - Apr 3, 2019

nothing display when i run my code idk why  🤮 some one help me ?

Quote:Error Message :
run:
BUILD SUCCESSFUL (total time: 1 second)

[Image: VGF2vVw.png]
[Image: a4G0z11.png]
[Image: OFpQpgJ.png]


RE: parallel processing thread - lockhead - Apr 3, 2019

I think you have to implement the run method like so:
Code
// Java code for thread creation by extending
// the Thread class
class MultithreadingDemo extends Thread
{
    public void run()
    {
        try
        {
            // Displaying the thread that is running
            System.out.println ("Thread " +
                  Thread.currentThread().getId() +
                  " is running");
  
        }
        catch (Exception e)
        {
            // Throwing an exception
            System.out.println ("Exception is caught");
        }
    }
}
  
// Main Class
public class Multithread
{
    public static void main(String[] args)
    {
        int n = 8; // Number of threads
        for (int i=0; i<8; i++)
        {
            MultithreadingDemo object = new MultithreadingDemo();
            object.start();
        }
    }
}



RE: parallel processing thread - 802.1X - Apr 3, 2019

Seems like you've created a class called "mythread", which has a method called runz().
When you go back to your "main" class you create the object "mythread" but you call function start(), instead of runz().


RE: parallel processing thread - Caliban - Apr 30, 2019

(Apr 3, 2019 10:01 AM)Kazzok Wrote:  Seems like you've created a class called "mythread", which has a method called runz().
When you go back to your "main" class you create the object "mythread" but you call function start(), instead of runz().

His class extends Thread so it already has the method start(), which calls run()

@OP you simply need to use the same name of the method you want to override, so run() not runz()