Solved

Synchronized threads

Posted on 1998-05-12
1
187 Views
Last Modified: 2010-04-16
I have this class that is instantiated multiple times.  Each instance needs to talk to the com port.  The problem I am having is synchronized only works on one object.   So what I am trying to figure out is how get get a group of the objects to be syncronized together.  Each instance will have one com port to be used.  So if two instances are not using the same com port there is no reason to synchronize.  Also instead of a com port it might be a socket.  

In other words how can I group objects together to be synchronized.

0
Comment
Question by:micah
1 Comment
 

Accepted Solution

by:
knollc earned 100 total points
Comment Utility
Hello,
  Try this:  have a static class that has one synchronized method: sendMsg().  On startup, have the static class grab on to the comm port, and all client objects wishing to send a message to the commport will use the static class' sendMsg() function.  Create one instance of the static class per COMM port that is available (I would name the class that hooks to a COMM port after the comm port it is controlling (ie, COMM1.sendMsg(SomeString), COMM2.sendMsg(SomeString), etc).  I hope this helps.

-Chris

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now