Java Interview Summary - Basics 1

  1. java multithreading - spin locks, lock bias

    Benefits: You can give contrast Servlet and CGI 
    difference between user threads and daemon threads: the user thread after the JVM will exit, then daemon threads will terminate (such as garbage collection thread), how to create a daemon thread in java
    creation methods: Recommended Runnable Interface; Inheritance thread; Callable (return value, used in conjunction with Future asynchronous) example
    lifecycle: New, Runnable, Running, Waiting , Blocked (join method), Dead (see below)
    priority: more dependent on OS threads scheduler, the best control of the code with their
    context switching (context-switching): return status of the CPU and memory
    to ensure the final termination of the main thread: join method of
    inter-thread communication: wait, notify, notifyAll (mainly between the thread-locking control)
    thread ways: sleep and yield is static, because you can only perform in executing thread


    Thread Safety

    How to ensure thread safety: atomic class, lock concurrency, volatile keyword reference links
    sync blocks and synchronization method: the tendency sync blocks, locks less
    ThreadLocal: do not want a lot of trouble when using synchronous global variable mechanism, you can use
    the deadlock: the investigation method (blocked thread locked resource id), java thread dump
    avoid deadlock: avoid nested locks, only lock used where needed, to avoid the wait indefinitely
    atomic operations: avoid data inconsistency (and other types of AtomicInteger) multiple threads, int ++ not atomic
    Lock Interface
    collection classes: are fail-fast ( a ConcurrentModificationException ), and the like may be used in a multithreaded ConcurrentMap

    Thread Pool

    Benefits: avoid running out of memory, can be recovered using the 
    method of creating: Executors
    blocking queue: thread-safe, can be used for producer - consumer issues
  2. spring boot - aop, ioc principle

    IOC: Inversion of Control, Injection or call the Dependency 
    the Spring of IOC: creating objects, controlled by the container are destroyed
    Principle: reflecting
    advantages: reducing the coupling, easier to maintain
    AOP: Aspect Orientied Programming, based on IOC 
    Features: Independent of the specific services, such as logging, permission checks, transaction management
    principle: dynamic proxy, static implantation (compiled after implantation)
    to achieve the Spring: JDK dynamic proxy (InvocationHandler and proxy class), CGLIB agent

  3. spring boot - on jpa, if logic and envisioned entirely correct, but the result is not correct, it should be how the investigation process

    Configuration: spring.jpa.show-sql
  4. Mybatis familiarity

    Mybatis Common Knowledge
  5. Work commonly used design patterns

    Creating type: Singleton, Factory, Abstract Factory, Builder 
    structure type: adapter, combiner, agents, decorators
    behavior: Visitors, viewers, strategy

     

  6. mysql - how to solve the million level data, queries are slow

    Cache 
    query optimization (index to avoid full table scan): Note that the index failed several cases
    database cluster (master / slave), database table hash, load balancing

     

  7. Degree of familiarity redis database

    Description: Redis is an open source (BSD license), the data structure stored in the memory system that can be used as a database, cache and messaging middleware. 
    Advantages: speed, support for many types of data, support services, expiration settings
    supported data types: string, hash, list, set , zset
    persistent way: RDB and AOF (see below)
    Note: Master best not write snapshots (will block the main thread) and AOF
    other: redis is a single-threaded process, with the queue control serial access

    Common Commands

    redis-cli -h host -p port -a password to start a client (without the local parameter) 
    of ping: Check redis service is started (return Pong)
    quit: Close connector
    select xx: Switch to the specified database

    keys pattern (such as keys * Search key)
    eXISTS key: whether key exists
    EXPIRE key seconds (timestamp): setting key expiration time
    PEXPIRE key milliseconds: invalidation of milliseconds
    the sET
    SETNX: If the key already exists, 0 is returned
    ...

    Cache Cache penetration and avalanche

    Cache penetrate the 
    general caching system, it is in accordance with the key to cache query, if the corresponding value does not exist, they should go to find the back-end systems (such as DB). Some deliberately malicious request query key is not present, a large amount of the request, it will cause a lot of pressure on the back-end systems. 
    This is called caching penetration. How to avoid?
    1 : null query result is also the case where caching and set shorter, or the data key corresponding to the dirty cache after the insert. 2 : is not present on certain key filtered. We can put all the possible key into a large Bitmap by the bitmap filter query. Avalanche cache when the cache server reboot or a large number of cache concentrated in one time period fail, so that when failure, back-end systems will bring a lot of pressure. Cause the system to crash. How to avoid? 1 : After a cache miss, by locking to control the number of threads or queue database read write cache. For example, a key for allowing only one thread to query the data and write cache, other threads wait. 2 : Make secondary cache, cache the original A1, A2 copy is cached, when A1 fails, access to A2, A1 cache expiration time is set short-term, A2 is set for long-term 3 : Different different key, set the expiration time for the cache invalidation time points as uniform as possible.

      

  8. Comparative RDB and AOF
     . 1 , aof file update frequency higher than rdb, aof preferably used to restore data.
    2 , AOF of more secure than rdb is greater
     3 , rdb performance better than the AOF of
     4 , if both are loaded with priority AOF

    RESP agreement

    RESP is a communication protocol used before redis client and server; 
    RESP features: simple, fast parsing and readable 
    the For the Simple Strings at The First byte of Reply at The IS  " + " replies 
    the For Errors at The First byte of Reply at The IS  " - " error 
    the For integers at The First byte of Reply at The IS  " : " integer 
    the For Bulk strings at The First byte of Reply at The IS  " $ " string 
    the For arrays at The First byte of Reply at The IS  " * " array

    Architecture type

    1 Single.
     2 master copy from: reduce the pressure reading, but can not solve the availability 
    3. Sentinel (Sentinel): automatic failover to ensure high availability
    4. Cluster (twemproxy)
    5. The clusters (straight type)

     

  9. Degree of familiarity with database mongodb
  10. linux familiarity
  11. docker - container principle 



reference:

Thread: https://www.cnblogs.com/dolphin0520/p/3932934.html

IOC: https://www.cnblogs.com/cyhzzu/p/6644981.html

AOP: https://www.cnblogs.com/lcngu/p/5339555.html

Design Patterns: https://www.cnblogs.com/jianzhixuan/p/9882756.html

MySQL query optimization:
    https://www.cnblogs.com/simadongyang/p/8205607.html

    https://www.cnblogs.com/fnlingnzb-learner/p/9939752.html

Redis:

    https://www.w3cschool.cn/redis/redis-ydwp2ozz.html

    https://www.cnblogs.com/jasontec/p/9699242.html

Guess you like

Origin www.cnblogs.com/roostinghawk/p/11963610.html
Recommended