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


Detect overtime the problem can make through redefine Wait() it returns variable of a Boolean (is not Void) will solve. Directive of return of value of a True is returned normally, and because False directive is returned overtime.

The concept of the conditional variable that is based on condition is very important. If this variable is installed,become False state, so the line Cheng that await will be broken by block, enter True state till this variable; Any conditions that await True await line Cheng variably to be able to be released automatically. (Below this kind of circumstance, wait() is called won't produce block to break. ) . Pass the grammar of following patulous Notify() , can support this function:

Nest monitoring lock decides an issue special trouble, I do not have simple settlement method. Nest monitoring lock is form of a kind of dead lock surely, when a certain lock when having line Cheng not to release a lock before hanging its oneself, can produce block of monitoring of this kind of nest. An example that this problem is below (still assume) , but concrete example is rife:

This is medium, two locks involve in Get() and Put() operation: One goes up in Stack object, another goes up in LinkedList object. The circumstance when the Pop() that we consider to try to call an empty inn when Cheng of a line below is operated. This line Cheng obtains these two locks, call Wait() to release the lock on Stack object next, but did not release the lock on List. If right now Cheng of the 2nd line tries to enter a boy or girl friend to stack middling pressure, it can be hanged forever on Synchronized(list) statement, and won't be allowed to approach a target forever. What await as a result of Cheng of the first line is empty inn of a blame, can produce dead lock so. This that is to say, cheng of the first line cannot be returned from Wait() forever, because holding a lock as a result of it, and bring about Cheng of the 2nd line to cannot run Notify() statement forever.

In this example, a lot of clear idea will solve a problem: For example, right any the method uses synchronism. But in real world, the means of settlement is not so simple normally.

A feasible method is, in Wait() according to all locks that release current line Cheng to get orderly instead, after should awaiting a condition to satisfy next, press afresh primitive get order to obtain them. But, I can imagine a code that uses this kind of means that I cannot understand simply to people, so I think it is not a truly feasible method. If you have good method, send E-mail to me please.

I also hope can when a day when undermentioned and complex condition is realized. For example:

Among them A, B and C are aleatoric object.

Modification Thread kind

The ability that supports type of race to control and Cheng of synergic type line at the same time applies in certain server is main demand in the program, wanting to make the system achieves the most high-powered circumstance to fall especially. I think Java programming language is in simplify the go too far on line Cheng model, and Java programming language should support the “ green of Posix/Solaris (” of Green) line Cheng and “ are light (concept of Lightweight) process ” (in “ (Taming Java Threads ” discusses in the first chapter) . This that is to say, some Java are fictitious the implementation of machine (the Java that goes up in NT for example is fictitious machine) synergic form process should be emulated in its interior, other Java fictitious machine should emulate Cheng of line of type of race to control. And it is very easy that to Java fictitious machine joins these expanding.
Previous 1 2 3 4 5 67 8 9 10 11 12 13 Next