Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2005

Tip: Looking for answers? Try searching our database.

Thread related question

Thread view: 
farseer - 08 May 2005 21:00 GMT
Hi,
suppose i have a class with member properties queueIn and queueOut.
Let's call this class "Server1".
When the app starts, this class has a "listen" method which is
basically a "while(true)" loop that runs until the app is forcibly
closed.

Now i have a Class that extends runnable.  Several of these classes
(let's call them ThreadClass) are instantiated and their purpose is to
access the queueIn and queueOut properties of the Server class.

My question is, if Server1's listen method (while loop) is always
running, and other threads try to access Server1's properties (queueIn
and queueOut), is there any performance issues?  can the fact that the
while loop is always running mean access to it's properties from other
threads will be affected or be slow?

thanks much
sameergn@gmail.com - 09 May 2005 01:03 GMT
Do you have any call in while (true) loop that blocks? like wait().
This will essentially give other threads a chance to run. Otherwise a
while (true) loop is kind of a tight loop which is CPU intensive.
Wibble - 09 May 2005 03:15 GMT
Its tricky to get this right.

AraryBlockingQueeu does exactly what you want.

http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ArrayBlockingQueue.html

> Hi,
> suppose i have a class with member properties queueIn and queueOut.
[quoted text clipped - 14 lines]
>
> thanks much
farseer - 09 May 2005 17:07 GMT
thanks for the responses.  I am not sure that i want anythig in
particular, just looking for advice from the experienced...so not sure
ArrayBlockingQueue is what i was looking for.  Basically, i would like
to know if there are performance issues with one thread accessing a
property of a class in another thread, if that class has a while loop
that is processing most of the time...for instance, below is the
scenario.  In this case, will ThreadC have an issue accessing the
Vector?  Now i realize that synchronzing may be an issue, but not
really asking about that...what i want to know is that when ThreadA
wants to access MyClass.list, does it have to wait for processing in
MyClass.process to finish doing 'somehting', or can it access it
immediately since it has a reference to it already?

class MyClass{
   public Vector list;

   public MyClass( ){ }

   public process( )
   {
       while ( true ) { \\do something that processes 90% of the time}
   }
}

class ThreadClass implements Runnable {

  private Vector pointerToMyClassVector;

  public ThreadClass( Vector list ) {
       pointerToMyClassVector = list;
  }

  public void run( ){
     ....
     list.add( xxx );
     ....
  }
}

....
void main ( String[] args )
{
    MyClass myClass = new MyClass( );
    ThreadClass threadC = new ThreadClass( myClass.list );
    ( new Thread ( threadC ) ).start( )
    myClass.process( );
}
Wibble - 10 May 2005 04:47 GMT
If your not synchronizing you can access it immediately.
That being said, you need to make sure its state isnt changing
while your accessing it.  Thats where synchronization comes in.
Usually you'll wrap critical sections within synchronize where
an object may be modified.  Synchronization isnt free,but it isnt
that expensive either.  Its like likely to have more of an affect
on latency than throughput.  An instance doesnt really live in a thread.
It lives on the heap.  The only thing really thread specific is
the current owner of a synchronization monitor.

> thanks for the responses.  I am not sure that i want anythig in
> particular, just looking for advice from the experienced...so not sure
[quoted text clipped - 43 lines]
>      myClass.process( );
> }
farseer - 10 May 2005 07:13 GMT
thanks much for the response.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.