Multithreading concurrency is generally not a programmer's decision, but a container decision.
Causes of multithreading failure:
Two threads access a data resource (critical resource) at the same time, resulting in inconsistent and incomplete data generation.
The inconsistency in data is often due to the fact that the two associated operations in one thread have only completed one step.
1 Packagetomtexts;2 3 4 classExceptionexam7_1extendsException//custom Exception class Exceptionexam7_15 {6 Private intShow;7Exceptionexam7_1 (inta)8 {9show=A;Ten } One PublicString toString () A { - return"Exceptionexam7_1 <" +show+ ">"; - } the } - Public classtomtexts_37 - { - Static voidCaculate (intAthrowsExceptionexam7_1 + { -System.out.println ("for [" + A + "] has done the appropriate operation"); + if(a>100) A Throw NewExceptionexam7_1 (a); atSystem.out.println ("Execute this algorithm to exit normally!") "); - } - Public Static voidMain (String args[]) - { - Try - { inCaculate (1); -Caculate (1000); to } + Catch(exceptionexam7_1 e) - { theSystem.out.println ("Caught exception" +e); * } $ }Panax Notoginseng}
Multithreading concurrency is generally not a programmer's decision, but a container-determined