Tag Archives: solution

CANNOT LINK EXECUTABLE: cannot locate symbol

This problem occurs in termux. You can’t locate the link library, that is, you can’t find the dependent library file. You just need to put the corresponding library in the environment variable.

If his error message contains   Referenced by/system/lib64 /, then add the corresponding location to the environment variable and execute the following command

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/system/lib64/

 

Termux installing redis

When I compile and install redis under termux, there are such errors as use of undeclared identifier.. my CC compiler and its dependent components are the latest version, but there are still problems. The reason is unknown. It indicates that the method is not declared at compile time. It is estimated that the CPU is weak and the compile execution order is related. It is just a guess.

Use the following solution directly:

apt install redis

That’s it. The bin executor is placed in usr/bin by default, and the configuration file is in usr/etc.

termux Failed to initialize runtime

Failed to initialize runtime solution appears when using ECJ or DX command in termux

The error report said that I had to check the log. Because I didn’t know much about Android system, I chose to check what ECJ did

Enter the path as shown in the figure

cd ~/../usr/bin

Cat ECJ later found that he was actually executing the command dalvikvm

So cat dalvikvm finds the following in this command

The two lines I marked had no comments

Open dalvikvm through VI or vim and comment out the above two lines. You can use it normally

Note out the following two lines

export ANDROID_ DATA=/data/data/com.termux/files/usr/var/android/
mkdir -p $ANDROID_ DATA/dalvik-cache

)You can use ECJ

Cause analysis:

Because the directory will exist after being used, the execution fails

 
Here is the original: https://github.com/termux/termux-packages/issues/1107

Java garbage collection

Most of the source network, I summarize, mainly in the interview garbage collection related to high frequency questions and answers

Common garbage collection algorithms

Mark clear algorithm

   mark clear algorithm scans from the root set (GC roots) to mark the surviving objects. After marking, it scans the unmarked objects in the whole space for recycling, as shown in the figure below. Mark and clear algorithm does not need to move objects, but only needs to deal with the non surviving objects. It is very efficient when there are many surviving objects. However, because mark and clear algorithm directly recycles the non surviving objects, it will cause memory fragmentation.

Replication algorithm

   replication algorithm is proposed to overcome the overhead of handle and solve the problem of memory fragmentation. At the beginning, the heap is divided into one object surface and several free surfaces. The program allocates space for the object from the object surface. When the object is full, the garbage collection based on copying algorithm scans the active objects from the GC roots and copies each active object to the free surface (so that there is no free hole between the memory occupied by the active objects), so that the free surface becomes the object surface, The original object face becomes a free face, and the program allocates memory in the new object face.

Mark tidy algorithm

   mark clean algorithm uses the same way as mark clean algorithm to mark objects, but it is different in cleaning. After reclaiming the space occupied by the non surviving objects, it will move all the surviving objects to the left free space, and update the corresponding pointer. Mark and clean algorithm is based on mark and clean algorithm, and moves objects, so the cost is higher, but it solves the problem of memory fragmentation. The specific process is shown in the figure below:

Generational collection algorithm

   generational collection algorithm is currently used by most JVM garbage collectors. Its core idea is to divide the memory into several different regions according to the life cycle of the object. In general, the reactor area is divided into the aged generation and the young generation, and there is another generation outside the reactor area that is the permanent generation. The characteristics of the old era is that only a small number of objects need to be recycled in each garbage collection, while the characteristics of the new generation is that a large number of objects need to be recycled in each garbage collection, so the most suitable collection algorithm can be adopted according to the characteristics of different generations.

Recycling algorithm of young generation

a) All newly generated objects are first placed in the younger generation. The goal of the young generation is to collect the objects with short life cycle as quickly as possible.

b) The Cenozoic memory is divided into one Eden area and two survivor (survivor0, survivor1) areas according to the ratio of 8:1:1. One Eden area and two survivor areas (generally speaking). Most of the objects are generated in the Eden area. When recycling, first copy the surviving objects in the Eden area to a survivor0 area, and then empty the Eden area. When the survivor0 area is also full, copy the surviving objects in the Eden area and survivor0 area to another survivor1 area, and then empty the Eden area and the survivor0 area. At this time, the survivor0 area is empty, and then exchange the survivor0 area with survivor1 area, that is, keep the survivor1 area empty, So back and forth.

c) When survivor1 is not enough to store the surviving objects of Eden and survivor0, the surviving objects are directly stored in the old age. If the old age is full, a full GC will be triggered, that is, the new generation and the old generation will recycle.

d) Cenozoic GC is also called minor GC. Minor GC occurs more frequently (not necessarily when Eden area is full).

Recycling algorithm of old generation

a) Objects that survive n garbage collections in the younger generation will be put into the older generation. Therefore, it can be considered that the objects stored in the old generation are all objects with long life cycle.

b) The memory is also much larger than that of the Cenozoic generation (the ratio is about 1:2). When the memory of the old generation is full, the major GC, or full GC, is triggered. The frequency of full GC is relatively low, and the survival time of objects in the old generation is relatively long, and the survival rate is high.

Recycling algorithm of permanent generation

   used to store static files, such as Java classes, methods, etc. Persistent generations have no significant impact on garbage collection, but some applications may dynamically generate or call some classes, such as hibernate. In this case, a large persistent generation space needs to be set to store these new classes.

 
 
Garbage collector

1、 Seven kinds of garbage collectors

(1) Serial (serial GC) – XX: + useserialgc

(Replication Algorithm)
the new generation of single threaded collector, marking and cleaning are single threaded, and its advantage is simple and efficient. It is the default GC mode of client level, which can be specified by - XX: + useserialgc .

(2) Parnew (parallel GC) – XX: + useparnewgc

(stop copy algorithm)
the new generation collector can be considered as the multithreaded version of serial collector, which has better performance than serial in multi-core CPU environment.

(3) Parallel scavenge (GC)

(stop copy algorithm)
parallel collector pursues high throughput and efficient utilization of CPU. Throughput is generally 99%, throughput = user thread time/(user thread time + GC thread time). It is suitable for background applications and other scenes with low interaction requirements. It is the default GC mode of server level, which can be specified by - XX: + useparallelgc , and the number of threads can be specified by - XX: parallelgcthreads = 4 .

(4) Serial old (MSc) (serial GC) – XX: + useserialgc

(tag collation algorithm)
the older generation of single threaded collector, the older version of serial collector.

(5) CMS (concurrent GC) – XX: + useconcmarksweepgc

(Mark clean algorithm)
high concurrency, low pause, pursuit of the shortest GC recovery pause time, high CPU occupation, fast response time, short pause time, multi-core CPU pursuit of high response time.

(6) Parallel old (parallel GC) – XX: + useparallelold GC

(stop copy algorithm)

The old version of collector, parallel collector, throughput first.

(7) G1 (jdk1.7update14 can be used for commercial use)

 

2、 1 ~ 3 is used for garbage collection of young generation: garbage collection of young generation is called minor GC

3、 4 ~ 6 is used for the garbage collection of the old generation (of course, it can also be used for the garbage collection of the method area): the garbage collection of the old generation is called full GC

G1 independently completes “generation by generation garbage collection”

Note: parallelism and concurrency

Parallel: multiple garbage collection threads operate simultaneously

Concurrency: the garbage collection thread operates with the user thread

4、 Five common combinations

Serial/Serial Old

Parnew/serial old: compared with the above, it’s just more multithreaded garbage collection than the younger generation

Parnew/CMS: a more efficient combination at present

Parallel scavenge/parallel old: a combination of automatic management

G1: the most advanced collector, but need jdk1.7update14 or above

5、 Serial/serial old

The young generation serial collector uses a single GC thread to implement the “copy” algorithm (including scan and copy)

The old generation of serial old collector uses a single GC thread to implement the “mark and tidy” algorithm

Both serial and serial old suspend all user threads (STW)

explain:

STW (stop the world): when compiling code, inject safepoint into each method (the point at which the loop ends and the method execution ends). When pausing the application, you need to wait for all user threads to enter safepoint, then pause all threads, and then garbage collection.

Applicable occasions:

CPU cores & lt; 2, physical memory & lt; 2G machine (in short, single CPU, the new generation of small space and STW time requirements are not high)

-20: Useserialgc: forces the use of this GC combination

-20: Printgcapplicationsstoppedtime: View STW time

6、 Parnew/serial old:

Parnew is the same as serial except that it uses multiple GC threads to implement the replication algorithm. However, the serial old in this combination is a single GC thread, so it is an awkward combination. It is not as fast as serial/serial old in the case of single CPU (because parnew needs to switch multiple threads), In the case of multi CPU, it is not as fast as the following three combinations (because serial old is a single GC thread), so it is not used much.

-20: Parallelgcthreads: Specifies the number of parallelgcthreads. By default, it is the same as the number of CPU cores. This parameter may also be used in CMS GC combination

7、 Parallel scavenge/parallel old:

characteristic:

The younger generation parallel sweep collector uses multiple GC threads to implement the “copy” algorithm (including scanning and copying). The older generation Parallel old collector uses multiple GC threads to implement the “mark collate” algorithm. Both parallel sweep and parallel old suspend all user threads (STW)

explain:

Throughput: CPU running code time/(CPU running code time + GC time) CMS mainly focuses on the reduction of STW (the shorter the time, the better the user experience, so it is mainly used to handle a lot of interactive tasks). Parallel scavenge/parallel old mainly focuses on throughput (the larger the throughput, the higher the CPU utilization, So it is mainly used to deal with a lot of CPU computing tasks and less user interaction tasks.)

Parameter setting:

-20: + useparalleloldgc: use this GC combination

-20: Gctimeratio: set the throughput directly. Suppose it is set to 19, then the maximum GC time allowed accounts for 1/(1 + 19) of the total time. The default value is 99, that is, 1/(1 + 99)

-20: Maxgcpause millis: maximum GC pause time. The smaller the parameter, the better

-20: + useadaptive sizepolicy: turn on this parameter, – XMN/- XX: survivorratio/- XX: preemptsizethhreshold these parameters will not work. The virtual opportunity will automatically collect monitoring information and dynamically adjust these parameters to provide the most appropriate pause time or maximum throughput (GC adaptive adjustment strategy). What we need to set is – Xmx, -20: + useparalleloldgc or – XX: gctimeratio (of course, – XMS is also specified to be the same as – Xmx)

be careful:

-20: Gctimeratio and – XX: maxgcpausemillis just set one

If – XX: + useadaptive sizepolicy, – XMN/- XX: survivorratio/- XX: preteuresizethreshold is not enabled, these parameters can still be configured. Take the rest server as an example

-Xms2048m -Xmx2048m -Xmn512m -Xss1m -XX:PermSize=256M -XX:MaxPermSize=256M -XX:SurvivorRatio=8 -XX:MaxTenuringThreshold=15 -XX:+UseParallelOldGC -XX:GCTimeRatio=19 -XX:+PrintGCDetails -XX:+PrintGCTimeStamps View Code

Applicable occasions:

In the case of many CPU computing tasks and few user interaction tasks, I don’t want to pay more attention to GC parameters, and I want to let the virtual machine do its own tuning work

 
When did GC trigger (one of the most common interview questions)

   because the objects are processed by generations, the garbage collection area and time are also different. There are two types of GC: scavenge GC and full GC.

  Scavenge GC

   in general, when a new object is generated and Eden fails to apply for space (if it is larger than the maximum space, start the guarantee mechanism. You can learn about the guarantee mechanism), scavenge GC will be triggered to GC the Eden area, clear the non living objects, and move the surviving objects to the survivor area. And then sort out the two areas of survivor. This way GC is for the younger generation

Springboot time zone problem

1. Add the

@PostConstruct

void   setDefaultTimezone()  {
  TimeZone.setDefault(TimeZone.getTimeZone(“Asia/Shanghai”));
}  
2. Add the

 ##  json   setting
spring.jackson.date-format=yyyy-MM-dd   HH:mm:ss
spring.jackson.time-zone=Asia/Shanghai  
 
3. Add the

public static void main(String[] args) {

    TimeZone.setDefault(TimeZone.getTimeZone(“Asia/Shanghai”));

  SpringApplication.run(BaseMicroServiceApplication.class, args);

}

 
// Otherwise, there will be 8-hour time difference on the server

Or in the database:

After logging in as root, set global time_ zone=’+8:00′;

 
 
Mysql database has time zone setting, and the system time zone is used by default

You can query the current time zone through the following statement

show variables like ‘%time_ zone%’;

Mobile phone code termux

Recommend two apps, termux and better terminal, and search directly in the app store.

The purpose of using this app is to let beginners experience learning Linux system, or let you have a portable server, intranet penetration and so on.

Below is how to turn on SSH

———————

With termux, you can easily convert your mobile phone into Linux to practice or learn

If you feel inconvenient, you can use Google input method or hacker input method

Feel not used to external keyboard, OTG adapter can be used, about five dollars look, very convenient, you can also read and write U disk

If you think the screen is small, you can use SSH to connect your mobile phone. You can use any SSH tool on your computer to connect your mobile phone

Common shortcut keys for mobile phone to operate termux——————–

The Ctrl key is a key commonly used by end users – but most touch keyboards don’t have it. To do this, termux uses the volume down button to simulate the Ctrl key.  
for example, on the touch keyboard, press to decrease the volume button+   L sends the same input as pressing Ctrl + L on the hardware keyboard.

Ctrl+A  -& gt; Move the cursor to the beginning of the line Ctrl + C  -& gt; Abort the current process Ctrl + d  -& gt; Log off terminal session Ctrl + e  -& gt; Move the cursor to the end of the line Ctrl + k  -& gt; Delete from cursor to end of line Ctrl + L  -& gt; Clear terminal Ctrl + Z  -& gt; Suspend (send sigtstp to) the current process

The volume up key can also be used as a special key to generate a specific input

volume + e  -& gt; ESC key volume + T  -& gt; Tab volume + 1  -& gt; F1 (and volume increase + 2 → F2, etc.) volume increase + 0  -& gt; F10 volume + B  -& gt; Alt + B, use readLine to return a word volume plus + F  -& gt; Alt + F, forward a word when using readLine volume + x  -& gt; Alt + x volume + W  -& gt; Up arrow key volume + a  -& gt; Left arrow key volume + s  -& gt; Down arrow key volume + d  -& gt; Right arrow key volume + L  -& gt; | ( Pipe character) volume plus + H  -& gt; 〜( Wave character) volume plus + U  -& gt; _ ( Underline character) volume plus + P  -& gt; Previous volume plus + n  -& gt; Next page volume up +.  -& gt; CTRL + \ \ (sigquit) volume + V  -& gt; Display volume control volume plus + Q  -& gt; Show additional key view

Suggestions———————————————————————–

It is recommended that beginners do not always run as root. If you want to use root, you can

su

After the command is switched to root

exit

Return to the original identity

 
Openssh needs to be installed in termux. As we all know, Linux has two major distributions.

General Command

uname -a

You can view the kernel information of this machine. For more details, execute the following command

 cat /proc/version 

For the convenience of operation, I use SSH to connect my Android phone,

Open SSH: I’m afraid this is the most detailed one for termux to open SSH

https://blog.csdn.net/qq_ 35425070/article/details/84789078

 

Solutions to the failure of installing jupyters in termux

When installing jupyter in termux, the network was cut off in the middle of the installation, which led to a day’s struggle. Finally, the installation was completed, and the problem was a. C   . H file is not available

Main reason: the dependency is not fully installed

Later, after some problems were solved, the installation of pyzmq (zeromq) got stuck, and the card owner did not move. Neither PIP install pyzmq nor PIP install jupyter alone could work

Follow these steps:

———————Check basic operations and commands:

pkg update

PKG install VIM curl WGet git unzip Unrar

———————Install dependency packages (5)

apt install python-dev clang fftw

apt-get install   libzmq

apt-get install   libzmq-dev

———————Install jupyter again

pip install –force-reinstall –no-cache-dir jupyter       // Force download and install again

 
========================================================
Using termux for Linux unfamiliar students can come to git this, a script written by high school students, fool type installation termux common tools

termux-tools-install

—————————————————————————————————————–

Other solutions reference:

Baidu reference here   http://www.drehere.com/?s=termux%20jupyter%20zmq

To re install termux: http://tieba.baidu.com/p/5537783650

Manual installation of zeromq (download source code analysis): there are a lot of online tutorials, just choose one: https://blog.csdn.net/n_ sev7/article/details/77320250

 
Other related issues: installing sketch, lxml, etc

https://www.jianshu.com/p/4deba3fad266

When installing pyaudio, an error is reported: failed error: portaudio. H: there is no such file or directory

When installing pyaudio, an error is reported: failed error: portaudio. H: there is no such file or directory

 
The operation of pyaudio depends on the portaudio library. You should first install a portaudio library

Portaudio installation steps:

A) Download PortAudio Library http://portaudio.com/download.html , select the latest tgz, upload it to Linux or termux and place it where you want to install it. Termux: I put it in/data/data/com.termux/files/usr/share, and CD it to this directory

B) tar – zxvf file name         Unzip the downloaded files without tar, such as apt get install tar

C) enter the decompressed portaudio file and execute the following commands in turn:

    ./configure

(configure command)

This step is generally used to generate makefile to prepare for the next step of compilation. You can control the installation by adding parameters after configure. For example, the code:./configure – prefix =/usr means to install the software under/usr, and the executable file will be installed in/usr/bin (instead of the default/usr/local/bin), The resource file will be installed in/usr/share (instead of the default/usr/local/share). At the same time, some software configuration files can be set by specifying the – sys config = parameter. Some software can also add – with, – enable, – without, – disable and other parameters to control the compilation. You can view the detailed instructions and help by allowing./configure – help.

In termux, this step is set to

./configure –prefix=/data/data/com.termux/files/usr

    make     compile

    make install     Installation

4. Install pyaudio library, PIP3 install pyaudio

Why interview requires reading the source code

Some people always think that when interviewing to build an aircraft carrier, you need to screw up your work. In the junior interview, you often ask, what is the life cycle of spring and what has been done since it was started, but it doesn’t matter at work. It’s useless and meaningless. Is that really the case?

Here is a small problem that can only be solved by understanding the initial sequence of spring.

Problem description

In the old version, obtaining a certain data XXX depends on a table tb in the database_ XXX, the new version requires to obtain these data by calling service_ B service interface. It’s reasonable to change bservice’s implementation class to interface mode, but after the change, we find that the application can’t be started! Error: DH handshake failed! I didn’t modify other logic, but I couldn’t start it, and the interface I called doesn’t need any encryption verification. As a fresh undergraduate who has been employed for less than two months, how can I solve this situation?

Background

Application introduction
our Java Web application service_ A is dynamic, the page is dynamic, the fields of the entity class are dynamic, the functions of an entity class and the services to be accessed are dynamic. You need to read the XML configuration file at startup to determine what the application looks like and what capabilities it has. The technology stack is SSM. In order to facilitate the natural loading of XML in @ postcut, That is, these XML configuration files are loaded after bean creation.

Requirements and changes
in the new version of the technology stack, we need to switch to spring boot, with some functional changes. Parsing these model configuration files actually depends on a table tb in the database_ XXX, the new version requires to obtain these data by calling service_ B service interface.

Introduction to service invocation
before calling other services remotely, you need to call addressing service first_ X address to obtain the protocol, IP, port and domain information of the target service, and then get the same address as the domain of its own service, and then get a callable instance of the target service according to the specified load balancing algorithm to call. The sensitive interface needs DH handshake and data encryption and decryption.


Problem orientation

I just changed a service method from database to interface, and the error was DH handshake failure. There was no change, which means that there must be something wrong with the interface call. Debugging found that the DH error occurred in the service addressing report, that is, the error occurred before entering the code I wrote, and the service addressing code was provided by the internal framework, Other people are also using the frame. Why didn’t other people respond?

Make a breakpoint in the addressing part of the framework code of idea decompilation, and debug step by step to find that the addressing service is being called_ The IP port of the target host can’t be found in X, but the framework code takes it directly from the cache. If it doesn’t, NPE will be thrown, and it will be thrown as a DH error by the upper layer. It is reasonable to say that there should be IP port information of addressing service in cache. Debug check shows that the cache is empty, size = 0, indicating that it has not been put in. Ctrl Alt F7 looks for a wave to see where the key pair will be put into the cache. It is found that the framework injects a bean: serviceinfolistener, which is executed after listening to the applicationcontextinitializedevent.

At this point, students who have read the spring source code or know what spring did when it started will immediately know what the problem is, because XML parsing is too early, and the dependent service addressing is not initialized at this time, so it cannot be called.


solve

Temporary scheme:
the parsing of XML will be delayed until the listener of the framework is finished.

The following scheme:
discuss with the framework group, the framework will rely on the addressing service_ The configuration time of X’s secret key pair is advanced to the after properties set of initializing bean, that is, the application developed with the framework is allowed to be called remotely at startup.

Solving Chinese garbled code in Java compressed file

Solving Chinese garbled code in Java compressed file

Introducing Maven dependency

<dependency>
    <groupId>ant</groupId>
    <artifactId>ant</artifactId>
    <version>1.6.5</version>
</dependency>

Click here to view all versions of ant on Maven’s official website

Using ant.jar class in ant

import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipOutputStream;

Replace the class in JDK API

import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

Summary and statistics of large amount of data

1. Try to implement group grouping in SQL. Although the database needs grouping operation, there is index in the database, so the operation speed is fast, and the number of records fetched to the report server side is greatly reduced, and the fetching speed is greatly accelerated. Therefore, when grouping operation is carried out on the report side, only a small number of records are needed, and the operation speed of the report is greatly accelerated.

2. To modify the expression of background color, use row () as little as possible. For example, calculate the line number in a grid of each line, and then judge the background color expression. The odd and even line judgment of background color, such as: if (row ()% 2 = = 0, – 3342337), is mainly row (), because this function can not optimize the calculation, and the number of expressions must be calculated as many times, and the calculation must be delayed after the expansion. In this way, if you expand more, it will have a greater impact on performance.

3. For cross grouping, the number of data sets should be reduced as much as possible, and single data set should be used as much as possible.