Position:Home>JAVA Development> The blemish of Java line Cheng
The blemish of Java line Cheng
From;  Author:Stand originally


To reading the internal support that keeps a lock

Read the idea that writes a lock to answer inside buy arrives in Java programming language. Read write implement the lock is in “Taming Java Threads ” (and elsewhere) in have bat around, say wraparoundly: One reads the support that keep a lock many lines Cheng visits a boy or girl friend at the same time, but there is Cheng of a line to be able to revise this target only in same hour, and cannot be revised when the visit undertakes. Read the grammar that writes a lock to be able to use Synchronized key word:

To an object, should be in only $writing piece in when doing not have line Cheng, just support many lines Cheng to enter $reading piece. When undertaking reading operating, one tries to enter $writing piece line Cheng can be broken by block, exit $reading till the Cheng that read a line piece. Should other line Cheng is in $writing piece when, try to enter $reading or $writing piece line Cheng can be broken by block, till this the Cheng that write a line exits $writing piece.

If read,awaiting with the Cheng that write a line, below default circumstance, the Cheng that read a line turns around undertake first. But, can use $writer_priority attribute to revise kind the definition will change way of this kind of default. Be like:

Visitting the boy or girl friend that founds partly should be illegal

Below current condition, JLS allows to visit the boy or girl friend that founds partly. For example, the line Cheng that founds in a tectonic function can visit the boy or girl friend that is being founded, make this object was not founded completely already. The result of code cannot decide below:

Setting X is - the line Cheng of 1 can be the line Cheng of 0 to undertake at the same time with setting X. So, right now the value of X cannot be forecasted.

It is to a means of settlement of this problem, before tectonic function was not returned, to the line Cheng that founds in tectonic function here, make its first step faster than calling the line Cheng of New already, also want to prohibit running its Run() method.

This that is to say, before tectonic function is returned, start() requests to must be deferred.

Additional, ying Keyun of Java programming language makes the synchronism of tectonic function. In other words, the code below (issue dispute standard in current condition) can work in that way like what anticipate:

I think the first kind of method is more concise than the 2nd kind, but it is more difficult that implementation rises.
Volatile key word should work in that way like what anticipate

JLS asks to withhold the request that handles to Volatile. Most Java fictitious machine is simple ground oversight this part content, this is not should. In multiprocessing implement below the circumstance, a lot of lead plane appeared this kind of problem, but it should be tried to solve by JLS originally. If you are interested in this respect, the Bill Pugh of Maryland university is devoting oneself to this job (consult please reference material) .
Previous 1 2 3 4 5 6 7 89 10 11 12 13 Next