Taking advantage of the National Day, the system sorted out their own in the development of the more commonly used class library, Linux command.
Sometimes, “a false alarm” is one of the most beautiful idioms in the world. It is better than being happy, colorful or smooth sailing. You know what loss is. These days, I feel even more so. May the sadness and fear be able to pass, and people outside the matter know how to cherish.
Java article
- Excel import and Export
This aspect is more commonly used is POI, EasyPOI, large file export. There are three core objects:
HSSFWorkbook: a version of excel prior to and including 2003. The extension is.xls. The upper limit is 65535 lines, exceeding which an error is reported.
XSSFWorkbook: this is a version after manipulating Excel2007 with the extension.xlsx. You can export up to 1.04 million lines, but when you reach a certain number of lines, you will also receive OOM, because the write operation is all in memory.
SXSSFWorkbook: also after manipulating Excel2007, handling large file exports. Handles writes to large files. The improvement is to persist data to disk during the write process to reduce the footprint on system memory.
- HttpClient tools
HttpClient is implemented in JDK11. Under JDK 11, we usually use Apache HttpClient.
- Date utility class
SimpleDateFormat Date Calendar
- Guava class library
The library is also a treasure trove, which reminds me of a scenario I encountered in my early days of work where arrays and lists were separated by commas.
I chose to implement it myself, and later found out that Guava had been introduced into the project, and Guava had done the functions. Something like this:
private static void joinerExample(a) {
List<String> stringList = new ArrayList<>();
stringList.add("aaa");
stringList.add("bbb");
stringList.add("ccc");
Joiner joiner = Joiner.on(",").skipNulls();
System.out.println(joiner.join(stringList));
}
Copy the code
Guava also has a built-in fixed sorting device. My project at that time also had such a requirement, such as sorting in a fixed order. For example, when input {north wind,1}, {west wind,2},{south wind,3},{east wind :4}, it was required to row according to the east wind, south wind, north wind and west wind, instead of the east wind, south wind and north wind being ranked last. Java’s built-in implementation is also possible, but with a bit of trickery, it’s easier with Guava. Apache Commons also provides a FixedOrderComparator.
- Use maven to search for Apache Commons-lang3 dependencies
This is another common library in development, and the one I use every day is StringUtils. This name corresponds to java.lang. Commons. Lang is roughly an extension of java.lang. So when you want to use the utils of some java.lang classes, don’t wrap them. Look under Commons-lang3 first.
- Apache commons-collections
This class library is an extension of the Java collection classes. Enriches Java’s collection types.
- Apache commons-codec
The tool class packages that handle common encoding methods such as DES, SHA1, MD5, and Base64.
- Apache commons-IO
File IO related
- Apache commons-math
Mathematics related: Mathematical analysis, linear algebra, Probability theory.
- Calculation tool class
NumberFormat Currency percentage related JDK built-in
- The graphics tool class Thumbnailator
Provides image rotation, cropping, compression.
- Serialization scenario
Jackson
Linux article
-
Df -h Check disk availability
-
PWD Displays the current path
-
Cat file name View the file contents and open the entire file. Use it with caution when the file is large.
-
Systemctl stop firewald. service Disables the firewall
-
Systemctl Status firewalld.service Displays the firewall status
-
Systemctl start firewalld Starts the firewall
-
Touch file name create file
-
More File name page to view the file content. Press space or Enter to continue loading the file content. Press Q to exit the view. When loaded at the end of the file, it automatically exits view
-
Less File name View the file content in separate pages. Press space to continue loading the file. Press q to exit the file
-
Head-n File name Displays the first n lines of a file
-
Tail -n File name N is a positive integer, indicating the last n lines of the file
-
Tail -f file name Dynamically view the last few lines of a file (while viewing the file, wait for the file to update, if the file is updated, the new content is displayed)
-
CD Directory path To enter a directory. The directory path can be an absolute path (all paths start with/are absolute paths) or a relative path. Relative path: the path starts with a non-/. For example, for the root user, ~ indicates the /root directory. For the bow user, ~ indicates the /home/bow directory
CD / # indicates the root directory of the system. CD usr/ # indicates the usr directory of the current directory. CD. # indicates the upper level of current directory CD.. /.. /usr/local/bin = /usr/local/bin = /usr/local/bin = /usr/local/bin # /etc # /etc # Represents the upper level of the current directory.. CD ~ # Indicates the root directory of the current user. (CD ~ has the same effect as running CD without adding a directory.) # Example: CD ~/data # Indicates the data directory in the root directory of the current user. For example, the root user is in the /root/data directoryCopy the code
-
Free-h Displays the system memory usage
-
JPS This command belongs to Linux. You can view Java processes running on Linux
-
The top command provides a dynamic real-time view of the running system
-
Ps – ef | grep process showed that the process of information.
-
kill -9 pid
SQL related
There is a one-to-many relationship, such as the student table and the grade table, where one student corresponds to multiple grades, but we want to show all of the student’s information and all of the grades in one row, separated by commas. The following database functions can help us achieve our requirements.
-
MySQL: group_concat([DISTINCT] join columns [Order BY ASC/DESC] [Separator ‘delimiter ‘])
-
Oracle: listagg(measure_expr,delimiter) within group ( order by order_by_clause);
Measure_expr: Can be an expression delimiter order_by_clause sorting field based on any column
- PostgreSQL : STRING_AGG ( expression, separator order by [order_by_clause] )
Expression column or expression, separator separator, order_by_clause sorting field.
Strategies for dealing with old data
When the old data was connected before, it involved more than ten tables, but I wanted to display it in one table, so I used Join. I expected that the query of this page would be slow eventually, and the result was just as I expected. Oracle has a syntax for materializing a view, which translates the view into a real table that periodically extracts data from the view. It’s a good way to work with old data. In addition, when docking old data, some one-to-many tables are built, such as personnel and department, the department code of personnel table is stored in a row, like the following:
name | deptCode |
---|---|
Zhang SAN 1 | 1, 2, |
Zhang SAN 2 | 1, 4 |
So if I’m looking for people in a certain department, we can actually do fuzzy matching, so let’s say this table is called Person, and we can write our query like this:
SELECT * FROM PERSON WHERE ‘, ‘| | deptCode | |’, ‘like’ %, 1, % ‘, under oracle | | oracle string concatenation symbol. MySQL requires contact for this function. 】
So if you want to realize in manipulation, we can use MyBatis to cycle this manipulation. SQL > select * from department 1;
SELECT * FROM country where CONCAT(', ',country,', ') like '%,A,%' OR CONCAT(', ',country,', ') like '%,B,%' mysql
Copy the code
Data rollback
Sometimes developers will delete or change data by mistake, which I have experienced deeply. Once when I was working on a project, I accidentally changed the whole table of a relatively core table, and I naturally thought of rolling back. Oracle provides a mechanism, called flashback in Oracle, to roll back a table to a specified time. There is support for other databases, but there are some differences.
Server request execution model
Almost every Java programmer knows the implementation process of Spring MVC. After all, this is a common knowledge in the interview. How about Tomcat? A classic interview question is what happens after a URL is typed into the browser. This is about the network and the front end, so let’s change the problem a little bit, so what happens when the front end or the browser requests a method of the Controller, to the method execution? Instead of thinking about page rendering, we’re just thinking about how the request goes to Tomcat or some other application server, from Tomcat to Spring MVC, to the method of execution, and what the execution flow looks like. We just add the following steps to the original Spring MVC execution flow:
- Request arrives at Tomcat
- Tomcat submits the request to the thread pool
- The thread pool selects any thread to execute the corresponding Servlet, the DispatcherServlet that calls Spring MVC
- So each request is executed by a different thread for the Controller
We can verify our claim by printing the name of the current thread in the request method. The code is fairly simple:
@RestController
public class HelloWorldController {
@GetMapping("hello")
public void test(a) { System.out.println(Thread.currentThread().getName()); }}Copy the code
Output:
The resources
- Java is specified in the order, there are many alternatives zhuanlan.zhihu.com/p/92149083
- Commons Math learning notes – directory (update) www.blogjava.net/changedi/ar…
- No time to explain! www.zhihu.com/search?type…