Stefan Müllerheim wrote:hi, i am looking for a solution to lock an object, but ( ) the object is a part of huge Vector, so i can't lock the entire huge Vector. instead i am looking for something like a method.
That's the wrong "instead". The right "instead" is "Instead, I will extract the object from the Vector and lock it."
Edit: by the way, your terminology indicates there is something you misunderstand. There is no such thing as a "dynamic" object. At least if you assign the usual meaning of "created at run time, not at compile time" to the word "dynamic". All objects are created at run time and I don't know of anything that can be used to characterize one object as "dynamic" and another object as "not dynamic". But you seem to be characterizing objects that way. Can you explain why? That misunderstanding might make your question go away.
Joined: Sep 17, 2010
sorry, for my bad terminology. i will try it better now.
there are lot of objects created to the runtime. therefore it is not possible to build a separate syncronized method for each object. but the object have to lock, due to lot of accessing threads.
my question is: is it possible to lock random objects? e.g. an objectbelonging flag (commonly semaphore) or a method by "lock" and "unlock for random objects?
i have read a lot about syncronization, but every lock is combined with a method or the access of several threads to the same moment, but nothing for a specific period (e.g. read, check, delete a Vector).
isn't been easy to describe my problem. hope it is easier to understand now.
thanks from a dark village in the countryside somewhere in Germany
Joined: Sep 17, 2010
i think i have got the solution...sometimes it is so easy, that becomes difficult.
but i need some confirmation for my "awarenesses".
conditions same: reading, checking, writing a Vector securly.
Q1. is it right that only one object may enter a synchronize block depending of the parameter?
Q2. i want overload the methode and synchronize block.
is the sync.block still enterable when an another object with an another(!) parameter try to enter?
A1. code below gave my answer to Q1, dump looks well.
conclusion: i became confused, due to the fact that a method like 'public synchronized void bla( Object obj )' let only one object entering at once, independent of parameter!