Multi-threaded thread pool

1. What is Java memory model?
    Java program to run on top of the Java Virtual Machine, Java memory model (Java Memory Model, JMM) is a kind of standard memory model in line, shielding the differences in access to a variety of hardware and operating systems to ensure that the Java program in each under kinds of platform access to the memory mechanism can ensure consistent results and norms.
2.MySQL transaction isolation level?
    MySQL transaction isolation level transaction isolation level In fact, with the spring, are 1, Read Uncommitted (read uncommitted content, also known as dirty reads), 2, Read Committed (read submission), 3, Repeatable Read (can be re-read, MySQL's default transaction isolation level), 4, Serializable (serializable)
principle of 3.Spring?
    Amount spring core and the AOP IOC, IOC and dependency injection is controlled inversion, the injection set can be divided into injection, injection constructor, interface injection. IOC is a container, is responsible for instantiating or configuration application objects and resume the dependencies between these objects. IOC's idea is: Spring to manage these objects only deal with their business relationship. Inversion of Control: way to get dependent reversal of the original programmers have to create their own objects to Spring to manage.
4. Why override equals to rewrite hashCode? (== comparison address, equals comparison object content)
    determine whether two objects are equal, the comparison is hashcode, if you override equals, hashcode but did not make a change, it may cause obviously two objects are equal , but not the same hashcode, cause can not be identified whether two objects are equal.
Several methods of 5.Object
    1.hashCode (): Get the user hash value is used to retrieve
    2.clone (): Creates and returns a copy of this object
    3.equals (Object obj): to indicate some other object is equal to this.
    4.getClass (): Returns the runtime class of this Object.
    5.toString (): Returns a string representation of the object.
    6.wait (): causes the current thread to wait until another thread calls the object's notify () method or the notifyAll () method.
    7.notify () and notifyAll (): single / wake all the threads waiting on an object's monitor
6. The dynamic agent in two ways, and the difference between
    the agent and is divided into JDK dynamic proxy cglib dynamic proxy
        JDK dynamic proxy can only achieve the class interface generation agent, and not on the class
        dynamic proxy class implements against cglib agent, mainly to generate a subclass of the specified class, a method wherein the covering is realized inheritance.
7. On the thread pool, create a thread in the thread pool process
    thread pool: it takes time to create a thread, if other tasks to create a go, efficiency was somewhat low, start from JDK1.5, Java API provides a framework for Executor You can create different thread pool.
    corePoolSize: a core number of threads, the number of tasks that can be executed simultaneously
    maximumPoolSize: maximum number of threads, show that the number of threads in the most that can be created
    keepAliveTime: idle thread retention time
    TimeUnit: Retention time in idle thread
    workQueue: blocking queue of waiting threads
    threadFactory: Create a thread factory
    handler: When the number exceeds maximumPoolSize task, the task of handling policy, the default policy is to refuse to add
    the implementation process: When the number of threads less than corePoolSize, each adding a task, it will immediately open thread execution; when corePoolSize full time, tasks will be added back into the buffer queue workQueue wait; when workQueue full time, to see if more than the number of threads maximumPoolSize, if exceeded, then refused to carry out, if not, create threads immediately.
8. CAS realization of the pessimistic lock and optimistic lock and optimistic lock operations
    pessimistic lock: always assume the worst case, each time to take the data will think others will modify the data, so each time you take the data will be locked so that others take time data will enter the blocked state, Java is the synchronized pessimistic locking. Relational database row locks, read locks, write locks are pessimistic locking.
    Optimistic locking: every time that others will not be modified, not locked, but when the update will determine what others during this period has not updated this data, optimistic locking for many types of reading can improve throughput when handling data the amount.
    CAS (Compare-And-Swap, Compare and replacement), which has three operands: memory address V, old expected value A, the new expected value B. Update variable, only when the actual value of the expected value of the variable A and V which memory addresses are the same, only the memory address corresponding to modify the value V B. Alternatively CAS values are atomic. CAS is optimistic locking technique, when multiple threads use CAS to update a variable, and if there is competition, there is no access to resources of the process will not be suspended immediately, instead of using thread to set to a state busy cycle, so over see if you can get a lock for some time, if you exceed the time suspended. ABA drawback is that there is a problem (from my memory objects in A becomes B becomes A, CAS will not change as a real change), long cycle time overhead large (and anticipation has been wrong, will always cycle)
9. What are the state of the thread?
    New status (new, the thread has not started), a ready state (Runnable, a new thread will not run automatically, you need to call the thread's start () method), operating status (Running, started run () method), blocking state (blocked, during operation, it may be due to various reasons into the blocked state), dead state (dead, run method denunciation, the thread is finished, or capture an aborted run method)
    reason for blocking states: 1. thread by calling sleep sleep method
            2. thread trying to get a lock, but the lock is being held by another thread
            3. thread is waiting for a trigger condition
difference 10.sleep and wait of:
    sleep () method belongs to the class of thread while the wait () method belongs to the Object class; sleep () method results in a specific time of the program be suspended, allowing the CPU to other threads, but has maintained his status monitoring, when the specified time arrives and automatically return to running , calling sleep () method of the process, the thread will not release the object lock; and when the call wait () method when the thread will give up the object lock, into After this object is waiting for the lock pool, only for this object to call notify () or notifyAll () method of the Thread object lock before entering the pool ready.
The 11.Java heap and stack
    each thread has its own stack memory for storing local variables, method parameters and the call stack, variables stored on a thread while another thread is not visible. The heap is shared by all threads of a common area of memory, objects are created in the reactor, in order to improve efficiency, the thread cache memory from the heap to its own stack, it could cause problems if multiple threads use the variable, then volatile variables come into play, which requires the value of the variable thread reads from main memory.
12. How to ensure the order of execution three threads
    with the Thread.join () method
13. how to detect whether a thread has a lock?
    java.long.Thread there is a method to holdLocak () method, the return value is a Boolean
    yield method of the Thread class can pause the currently executing thread object, let the other have the same priority thread execution
14. How to avoid deadlocks
    multithreading deadlock: refers to the case of two or more processes in the implementation process, a result of competition for resources caused by waiting for each other. Deadlock must meet the following criteria:
    1. mutually exclusive conditions: a resource can only be used by a process
    2. Request and maintain the condition: When a process is blocked because the requested resource, the resource has been kept hold
    3. not deprivation: the process has access to resources, not used before, can not deprive the
    4 cycle wait condition: formed between several processes one kind of end to end cycle of waiting for a resource relationship (I understand the infinite loop ...)
    the most simple solution: wait condition blocking circulation to a certain order to operate
15. What mode when blocking
    blocking mode means that the program will wait until the process is completed can not do other things during.
What degree of concurrency in ConcurrentHashMap 16. java that?
    ConcurrentHashMap divided portions will actually map to achieve its scalability and security thread, this division is obtained by using the degree of concurrency, which is an optional parameter ConcurrentHashMap class constructor, the default value is 16, which may be a multi- thread the case be able to avoid lock contention.

Guess you like

Origin www.cnblogs.com/tk970803/p/11084847.html