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 / November 2006

Tip: Looking for answers? Try searching our database.

vectors an synchronizing....

Thread view: 
nullstring - 21 Nov 2006 16:06 GMT
Hello together (at such a sunny day:)

I have a question about multithreading!
I want to make a variable count of threads using an (self-implemented)
dbhander-class.
But I don't want to work with 'synchronized', because of the
performance...

So, when I add a new jdbc-connection in a vector for every new thread,
and all threads work with its own connection, but in the same vector!
Do I have problems with synchronizing?

If I work with the same connection from different threads, YES! (<- I
think)
But only with the same vector????

thanks in advance....
Nullstring
Robert Klemme - 21 Nov 2006 16:20 GMT
> Hello together (at such a sunny day:)

It's dark here.

> I have a question about multithreading!
> I want to make a variable count of threads using an (self-implemented)
> dbhander-class.
> But I don't want to work with 'synchronized', because of the
> performance...

What do you mean by that?  You need to use synchronize one way or
another if you want to share a resource thread safe (leaving out
volatile etc.).  And the performance penalty is negligible - unless you
hold the lock for the complete course of action.

> So, when I add a new jdbc-connection in a vector for every new thread,
> and all threads work with its own connection, but in the same vector!
> Do I have problems with synchronizing?

All Vector methods are synchronized.  I don't see how that should create
a problem.  But then again it is not very clear from what you write what
you want to do.  Is your Vector some form of connection pool?  If so,
there are plenty implementations out there - even free ones.  And they
have all the whistles and bells...

> If I work with the same connection from different threads, YES! (<- I
> think)
> But only with the same vector????

You cannot use a JDBC connection from multiple threads /at the same time/.

Regards

    robert
Eric Sosman - 21 Nov 2006 16:43 GMT
nullstring wrote On 11/21/06 11:06,:
> Hello together (at such a sunny day:)
>
[quoted text clipped - 3 lines]
> But I don't want to work with 'synchronized', because of the
> performance...

   Then make sure the "variable count" is always equal to one.

> So, when I add a new jdbc-connection in a vector for every new thread,
> and all threads work with its own connection, but in the same vector!
> Do I have problems with synchronizing?

   The methods of java.util.Vector are synchronized, so no
individual method call will get into thread trouble.  However,
sequences of method calls can still produce "problems with
synchronizing."

> If I work with the same connection from different threads, YES! (<- I
> think)
> But only with the same vector????

   I'm not 100% sure what you're asking here, but I think the
answer is "Yes, you have problems with synchronizing."  (Reason:
your understanding of threads and synchronization is incomplete,
which means you've probably made mistakes.  You need to learn
more about threads to improve your chances of success.)

Signature

Eric.Sosman@sun.com

Karl Uppiano - 21 Nov 2006 20:29 GMT
> But I don't want to work with 'synchronized', because of the
> performance...

If by "performance" you mean "corrupt the data as rapidly as possible", by
all means, let her rip. You either need synchronization or you don't. You
need it if you have two or more threads attempting to access the same
resource. You don't need it if the threads accessing entirely different
resources. It isn't your choice.

I'll qualify that last statement: It might be your choice if you can think
of a way to arrange for the resource not to be shared, or in the extremely
rare and somewhat implementation-dependent case where you can guarantee that
access to shared data is intrinsically atomic.


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.