Multithreading concurrency is generally not a programmer's decision, but a container-determined

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.