Java multithreaded programming core technology is too detailed

Day to fly

  • java
  • string
  • static
  • class
  • void
  • test
  • thread
  • service
  • Synchronized

Abstract: A synchronized keyword, can speak more than 100 pages, made dozens of small examples. I am!

A hundred pages of synchronized, dozens of small examples.

I am!

But really rehearsing it all the way,

You’ve learned a lot about this key application scenario.










package test; public class Service { private boolean isContinueRun = true; public void runMethod() { String anyString = new String(); while (isContinueRun == true) { synchronized (anyString){ } } System.out.println("have stopped."); } public void stopMethod() { isContinueRun = false; }}Copy the code





package test; public class ThreadA extends Thread { private Service service; public ThreadA(Service service) { super(); this.service = service; } @Override public void run() { service.runMethod(); }}Copy the code






package test; public class ThreadB extends Thread { private Service service; public ThreadB(Service service) { super(); this.service = service; } @Override public void run() { service.stopMethod(); }}Copy the code





package test; public class Run { public static void main(String[] args) throws InterruptedException { // TODO Auto-generated method stub try { Service service = new Service(); ThreadA a = new ThreadA(service); a.start(); Thread.sleep(1000L); ThreadB b = new ThreadB(service); b.start(); System.out.println("have set stop order."); } catch (InterruptedException e) { e.printStackTrace(); }}}Copy the code






For details, please click
Comments (0)

To:


Related articles

  • Ali Cloud customer case study: Luoji Thinking
  • Several recommended Java books
  • To become a top Java programmer, read these 11 books
  • Some good books for Java geeks to read
  • VC++ learning methods and books recommended.
  • Java programmers must have a list of books
  • Java book recommendations, comprehensive explanations of methods and processes
  • April Fool’s Day boss announced, free book + free entry Java knowledge planet…
  • These asynchronous books you’ve been longing for are finally out!
  • To become a top Java programmer, read these 10 books

The net friend comment on