Java Basics---Multithreading---fine-grained summary

Source: Internet
Author: User

Tag:==    method     has a    set   ring    Constant pool     address space     operation    DEF   

= = =? 2.1.1===? How to understand variable thread safety inside a method, instance variable non-thread safe? In-method variables are local variables within each method and must be thread-safe. instance variables, because different threads can access these instance variables concurrently, so there is a non-thread-safe issue.  ===? Why is the int type and string type properties not available as synchronous monitors? Imagine creating two references to the string "abc" at the same time, but because the Java virtual machine has a constant pool, which is equivalent to two references to the ABC string in the string constant pool, there is a synchronous effect when using two references as monitors. But the intent is to have these two references exist as two object locks.  ===? What is the difference between a class lock and an object lock? Where do class locks fit in?  What are the two forms of class locks? Because a class is instantiated no matter how many times, the static method and the static variable are only one copy in memory. So, once a static method is declared as synchronized. All instantiated objects of this class call this method, sharing the same lock, which we call the class lock.       Because each Java class has a class object, the static method of the class requires a class object. So the class lock is actually the lock of the class object.  ===? What is the atomicity and visibility of threading operations? Atomicity: The operation can no longer be split. Non-atomic operations will be wired to secure the issue of visibility: thread modification State Other threads can also see  ===? How do you understand that interrupt () causes the blocked thread to break without stopping a running thread? Which state of the thread will be interrupted? The interrupt () method allows the blocking thread, that is, the thread waiting in the synchronization queue to break the threads thread = new Thread (), Thread.Start (); Thread.inturrupt (); 1. A running thread is not interrupted , only one interrupt signal will be thrown to the blocked thread. The goal is to get the blocked thread out of the blocked state. 2. If the thread is blocked by Wait,join or sleep three methods, it will accept an interrupt exception and exit the blocked state early. This.interrupted () returns TRUE or FALSE to determine if the interrupt is interrupted and the interrupt flag is canceled. This.isinterrupted () Determines whether the interrupt is interrupted and does not cancel the interrupt state.  ----What are the differences between threads and processes, threads and processes? A thread is the smallest unit of operating system operation scheduling. A process is a separate function of a program's running activity on a data collection. Process can haveMultiple threads, processes have separate address spaces and memory units, and multiple threads can share memory.   What is the difference between the Run method----thread and the Start method? First the corresponding thread state is not the same as start () corresponding to the executable state, used to start a thread, start internally called the Runrun method does not start the thread, but only in the original thread execution.  ---The difference between the callable interface and the Runnable interface? Callable interface 1. You can return the parameter 2. Exception runnable interface 1. No return parameter 2. An exception cannot be thrown, and an exception must be handled internally. Definition and solution of   === race condition when multiple threads access a public resource, a race condition occurs if there is a sequential requirement. The code that produces the race condition is the critical section. The problem of race condition can be solved by adding synchronous code on the condition of race state.  === the concept of deadlock and starvation? deadlocks, threads waiting for each other to release locks cause stagnation. Hungry, part of the thread has been acquired without locking causing stagnation.   How threads handle run-time exception http://blog.csdn.net/hqq2023623/article/details/509895411. Inherits an interface Uncaughtexceptionhandler, Implementing the Uncaughtexception Method 2. Thread set exception handling T.setdefaultuncaughtexceptionhandler (new Threadexceptionhandler); 

Java Basics---Multithreading---fine-grained summary

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.