• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

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 :(

Thanks
0
Kejtar
Asked:
Kejtar
  • 3
  • 2
  • 2
  • +1
3 Solutions
 
Manikandan ThiagarajanSenior consultantCommented:
0
 
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.
0
 
Giant2Commented:
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Manikandan ThiagarajanSenior consultantCommented:
0
 
Mayank SAssociate 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.
0
 
KejtarAuthor Commented:
Thanks guys, I'll give it a shot over the weekend and see where that takes me.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Ok, sure.
0
 
Giant2Commented:
ok.
0
 
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now