I have a program and i want to have multiple threads, but i want to create them in the same class, can i do this? or do i have to make a class that implements runnable and just create new instances of that in my current class?
I'm not 100% sure about what you want, but let me take a shot. You need to create your "threads". To do that, you can either implement the runnable interface (as you said) or you can extend the Thread class. If your class (suppose it's called MyClass) already extends Thread, you can just instantiate as many MyClass's as you want from inside of it (is that what you mean by "the same class")?
What i understand from the above discussion is that you want an instance of your class to operate under a multi threaded environment, and you are confused as to whether you need a separate class to do so. If that's it, then you don't necessarily need it. Your class can implement Runnable or extend Thread and, well, Vroom, your code works....
You show your constructor making another new A. What's going to happen in that constructor? Do you see a potential problem?
Yes, you need to look into start(). You don't write start, but you call it on the Thread. start() does some deep magic, gets a new thread running and finally calls run(). As you did in your template, that's where you do the real work.
So let's start a thread with this instance of A, not a new one:
There may be some risk here that the new thread will start A running before it is fully initialized by the constructor. That could be bad.
This doesn't feel like a good design. SomeOtherClass would create an instance of A and it would be off and running on another Thread before SomeOtherClass knows what's happening. Seems wrong. Just creating an object shouldn't be enough to make so many other things happen.
Why are you so interested in not using any other classes? Is it important to avoid the typical:
new Thread( new A( args... ) ).start();
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi