Threads and classes?

OK, I picked up a mindstorm set just to play around with and not too long after I found out that I can get rid of their WYSIWIG programming interface and program it in lejos which is java based language and I really bit the bug..... I've played with some basic stuff which was simple and now I kind of got in in over my head but it's so much fun I don't want to put it away.

So the real question is how do I deal with classes and threads?  I want to setup a main control class which has sets up the environment and then interacts with two or more separate classes.  Each class would run in it's own thread and would deal with either an input devidce (sensor type for most part) or output (mostly motor, but also maybe a light).  I tried looking for simple examples of what the structure/layout should be and I could not find anything.  So....  any pointers, preferably skeleton examples that anyone can point me to??  

Oh yeah, last time I played with java was just about when I took a college course 6 years ago.... and threads weren't really covered :(

Who is Participating?
Mayank SConnect With a Mentor Associate Director - Product EngineeringCommented:
>> but my problems arise when I"m dealing with more then one class and each running as a thread and interacting with the original class.  

Keep the original class as a singleton and maintain one global instance of it, accessible from everywhere. Let it instantiate the other threads and maintain a handle to them in a hash-table or something.
Manikandan ThiagarajanConnect With a Mentor Senior consultantCommented:
KejtarAuthor Commented:
Thanks, but my problems arise when I"m dealing with more then one class and each running as a thread and interacting with the original class.  Making the single class a thread is not a big deal.
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Giant2Connect With a Mentor Commented:
You can use "synchronized mechanism" on your main class methods and pass a reference of your main class to both thread.
In this manner each thread can reach the main class methods.

Hope this could help you.
Bye, Giant.
Manikandan ThiagarajanSenior consultantCommented:
KejtarAuthor Commented:
Thanks guys, I'll give it a shot over the weekend and see where that takes me.
Mayank SAssociate Director - Product EngineeringCommented:
Ok, sure.
KejtarAuthor Commented:
Sorry to leave that question hanging for so long, but I haven't had a chance to get back and play with it again.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.