Sophisticated interview questions (a)

The difference between the three jdk jre jvm

The JVM  : English name (Java Virtual Machine), that is, we are familiar with the Java virtual machine. Understanding xxx.class only this type of file, it is possible to class bytecode instructions file to identify and invoke the operating system API-up operation is completed. So, jvm is the core Java cross-platform, and will be described in detail below.

The JRE  : English name (Java Runtime Environment), we call it: Java Runtime Environment. It mainly consists of two parts, jvm standards and achieve some basic Java class libraries. It jvm relative, the extra is part of the Java class libraries.

The JDK  : English name (Java Development Kit), Java Development Kit. jdk Java development is the core, which integrates jre and some nice gadgets. For example: javac.exe, java.exe, jar.exe like.

Clearly, the relationship between the three is: layers of nested relationship. The JDK> the JRE> the JVM .

 

Why is the number of copies of HDFS 3, why not 2 or 4?

HDFS default number of copies is 3, 3 is not necessary.

Hdfs modify the number of copies, the first thought is to modify the parameters dfs.replication hdfs-site.xml in

HDFS reliability using an optional rack sensing strategy referred to improve data availability and utilization of network bandwidth.

In most cases, HDFS copy factor is 3, HDFS storage strategy is a copy stored on the local node chassis, another copy is stored on another node in the same frame, and the third copy is stored in different node on the rack. This strategy reduces the data transmission between the rack and improve the efficiency of the write operation. Rack error probability small probability of error than the node, so this policy does not affect the reliability and availability of data. At the same time, because the data exists only on two racks, this strategy reduces the network bandwidth required for reading data.

In this strategy, the copy is not evenly distributed in the rack. In this strategy without damaging the reliability and reading performance, improved write performance.

 

How how to view the port numbers to view the process

Check the port number netstat -anp | grep port number

ps -aux | grep *** *** For more information query process

ps -aux-memory query process information

View java process

ps -ef | grep java

jps

 

MR works

A little, check the information before.

 

Applications said hidden under the semantic model

Belonging recommendation system algorithm, in conjunction with their project application cases need to be expanded. (If he wrote the words of the project.)

The core idea of ​​LFM (latent factor model) Implicit semantic model is to contact the user's interest and features articles by implicit (latent factor), adopt based on user behavior statistics automatic clustering.

        Latent semantic analysis techniques from statistical classification of user behavior, on behalf of the user views on the classification of goods. Similar latent semantic analysis techniques and ideas in ItemCF classification of goods, if two items are like many users at the same time, these two items will likely belong to the same class.

        Latent semantic analysis technology allows us to specify how many of the final classification, the higher the number, the more fine grain size classification, anyway, the more coarse particle size classification.

        Latent semantic analysis techniques calculates the weight of each item belonging to the class of weight of each article and therefore is not to be assigned to one hard class.

        Implicit semantic analysis of each classification are not given the same dimension, which is calculated based on the common interest of the user, if the user is a common interest in one dimension, then the LFM class is given the same dimensions.

        Latent semantic analysis techniques can determine the right items in each weight class, if you like a certain type of user will like an item, then that item right in this class of weight it may be relatively high statistical user behavior.

 

Java development before?

General recommendations developed over the answer, such as we have in the development of Hive UDF function, write HDFS API, when HBase API, are developed using Java. Before using Java also wrote a simple class interface code.

Multithreading is how it works.

   Multithreading advantages are:

    You can not share data between (1) a process, a thread can;

    (2) The system creates a process to re-allocate system resources required for the process, so the cost of creating a thread is relatively small;

    (3) Java language built-in support for multi-threading capabilities, simplifying the java multithreaded programming.

Thread of the life cycle:

 

 

1, the new state

       After establishing a thread object and using new Thread class or subclass, the thread object is nascent state. Thread nascent state has its own memory space, enter the ready state (runnable) by calling the start method.

Note: You can not thread has been started calling start () method again, there would be the Java .lang.IllegalThreadStateException abnormal.

2, ready state

       The thread in the ready state already has operating conditions, but not yet assigned to the CPU, the thread in the ready queue (queue form employed although, in fact, it may be called cell instead run to run queue is not scheduled because the cpu FIFO order must be scheduled), the system waits assigned CPU. The state is not waiting execution state, when the system is waiting for a Thread object is selected executed, it will enter the execution state from the waiting to be executed, the system selected action called "cpu scheduling." Once the CPU, thread enters running state and automatically call their own run method.

Tip: If you want to run immediately after sub-thread calls start () method, you can use Thread.sleep () mode so that the main thread to sleep for a Huoer, turn to execute child thread.

3, operating status

      Thread running the most complex, it can become blocked state, ready state, and the state of death.

Thread in the ready state, if obtained cpu scheduling, will run from the ready state to state, execution run () method in the task. If the thread is lost cpu resources, it will run and from the state to the ready state. Re-allocation of resources to wait for the system. You can also call the state of threads running yield () method, it will make the cpu resources, it becomes ready again.

In the event of a case, the thread will be blocked from running state to state:

     ①, thread calls sleep method give up occupied system resources

     ②, IO thread calls a blocking method, before the method returns, the thread is blocked

     ③, trying to get a thread synchronization monitor, but change the synchronization monitor is being held by another thread

     ④, the thread is waiting for a notification (notify)

     ⑤, the program calls the suspend method thread thread suspended. However, this method is easy to cause a deadlock, so the program should try to avoid using this method.

When the thread run () method executed, or is forcibly terminated, such as abnormal, or by calling the stop (), desyory () method, etc., it will be transformed from a running state to the state of death.

4, blocking state

      Thread running in certain situations, such as performing a sleep (sleep) method, or wait for resource I / O devices, etc., and will allow the CPU to temporarily stop their run into the blocked state. 

Thread blocking state can not enter the ready queue. Only when the cause of obstruction of elimination, such as sleep time is up, or wait for the I / O device idle down, the thread into the ready state, again into the ready queue waiting in line, after being selected from the original system stopped position continue to run. There are three ways to perform pause Threads:

5, the state of death

      When the thread run () method executed, or is forcibly terminated, it is considered dead. The thread object might be alive, but it has not a single thread of execution. Upon the death of threads, it is final. If you call start on a dead thread () method throws an exception java.lang.IllegalThreadStateException.

 

Thread creation and start-up mode:

1) Create a thread class inheritance Thread class

By inheriting concrete steps and specific code Thread class Thread class is created as follows:

   • Define a subclass inherits the Thread class, the class and override run () method;

   • Create an instance of a subclass of Thread that created thread object;

   • call the thread object's start () method to start a thread.

2) implement Runnable interface to create thread class

Through specific steps and specific code implementation Runnable interface created thread class is as follows:

   • defined class that implements Runnable interface, the interface and override run () method;

   • Create an instance of Runnable implementation class and use it as an example of Thread of the target object, that is, the Thread object is the real thread object.

(3) create a thread through Callable and Future

By concrete steps and specific code Callable and Future create a thread as follows:

   • Create Callable interface implementation class, and implements call () method, the call () method as a thread of execution, and return a value.
   • Create an instance of the implementation class Callable using FutureTask packaging Callable object class, the object encapsulates FutureTask Callable object of the call () Returns the value of the method.
   • Use FutureTask objects to create and start a new thread as the target Thread object.
   The returned values after the end of the implementation • Call FutureTask object get () method to get the child thread

 

Thread Management

Thread sleep --sleep

Thread concession --yield

Thread merger --join

Priority thread

Background (daemon) thread

 

Thread Synchronization

 java multithreading allows control, when a plurality of threads operating variables shared resources (e.g., additions and deletions to change search data) will result in inaccurate data, conflict with each other, so as to avoid the addition of the synchronization lock before the thread is not finished, it is called by other threads, thus ensuring the uniqueness and the accuracy of the variable.

1, synchronized method     

      That is synchronized keyword modification method. Since each object of the java has a built-in lock, when using this keyword modification methods, built-in locks protect the entire method. Before calling this method, you need to get the built-in lock, otherwise it is blocked.

public synchronized void save(){}

 Note: synchronized keyword static methods can also be modified, if the static method call at this time, it will lock the entire class

 2, the synchronization code block     

     That is synchronized keyword modified block. The modified block of statements that keyword will be automatically locked with built in order to achieve synchronization.

3, using a special field variables (volatile) implement thread synchronization 

4, using the reentrant lock (Lock) to achieve thread synchronization

One of the most multi-threaded java like to ask questions. Detailed look link

https://www.cnblogs.com/snow-flower/p/6114765.html

Guess you like

Origin www.cnblogs.com/lingboweifu/p/11909765.html