Some Java interview questions (to be continued)

computer network

Basic knowledge of computer network interview

Basics

Collections Framework

Multithreading

  1. Thread class sleep () wait methods and objects () method can allow a thread suspended, What's the difference?
  • leep () method (sleep) is a thread class (Thread) static method, this method is called the current thread will suspend execution of the specified time,
    the opportunity to perform (CPU) to give other threads, but the lock object remains, therefore dormant It will be automatically restored after the end of time (the thread back to the ready state).
  • wait () method of the Object class, call the object's wait () method causes the current thread to give up the object lock (thread suspended), enter the object wait pool (wait pool), only call the object's notify () method (or notifyAll waiting to wake up the thread pool, etc. should lock pool (lockpool) when () method), if the thread regain lock objects can enter the ready state
  1. sleep (thread) method and the yield () method What is the difference?
  • ① sleep () method to other threads a chance to run without regard to priority thread, so that will give the opportunity to the low priority thread to run; yield () method only to the thread of the same priority or higher priority to run Opportunity;
  • After executing thread ② sleep () method into the blocked (blocked) state, and after the implementation of yield () method into the ready (ready) state;
  • ③ sleep () method declaration throws InterruptedException, while the yield () method does not declare any exceptions;
  • ④ sleep () method is more portable than the yield () method (associated with the operating system, CPU scheduling).
  1. Talk about the views of the java

  2. HashMap
    split into Hash and the Map
    Hash: Hash value -> is converted into an arbitrary length to a fixed value by an algorithm (hash function algorithm).
    Map: key-value pair <k, v> storage
    Summary: Hash out value, and then positioned by the Hash value to the value stored in the map and the map.

Guess you like

Origin www.cnblogs.com/amelie-/p/10962184.html