I am relativity new to multithreading in Java, and I would like to know if it is possible to execute a method within a class in parallel. So instead of this:
public void main() {
this.myMethod();
this.myMethod();
}
... where each method within the class is fired after the previous call has finished, that they would be done in parallel. I know the following example can be done, but that involves creating new classes, which I would like to avoid:
public class HelloRunnable implements Runnable {
public void run() {
System.out.println("Hello from a thread!");
}
public static void main(String args[]) {
(new Thread(new HelloRunnable())).start();
}
}
Just to be clear, I have seen this example, but it was of no help me to me.
Is the key to cracking this issue involve using public static methods? Either way, could someone please provide an example how to do this with their solution?
Thank you for your time!