The scaffolding that has long dominated the javaee field has led with spring struts2 mybatis/hibernate;
Spring:
Spring is not just for Java services. As the implementation of spring as a cgi standard, it is not just a framework in the Java field, but the C# platform can still benefit; spring provides various convenient annotation configuration methods such as abstraction or bootde integrated solutions, which greatly simplifies the project basis of Javaee;
During the use of spring, the two sides are differentiated, some are light-weight annotations, and some are tending to be full annotations.
First of all, the premise of annotation is that it must go through proxy, dynamic, static, and cglib proxy. For lightweight annotations, the angle is static or one-time annotations.
For example, controller annotations, these one-time annotations or compile-time annotations are initialized in the project context as an implicit one-time scan, and related annotations such as service, providing singleton lightweight object instances. Considered as the first choice. This reduces the cost of proxy and reflection during the runtime period, and also saves better resources for the runtime stack.
Another type, such as responsebody, is a dynamic annotation or run-time annotation. Each time you request, the reflection of the annotation will be executed. The annotation of the running period is of course to occupy resources.
In general, not necessary annotations can be completely ignored. Based on the request and response method based on the servlet basics, there is no mvc, which cannot be solved, taking parameters, passing parameters, returning, etc., and there is no need for annotations during the runtime. Annotations during the runtime seem to reduce the amount of code. In order to make up for the various shortcomings in this process, a dynamic annotation of a circle will be run to execute an annotation that you use inside the method. For param annotations written in the method, what code is missing compared to using request get yourself? It is just that the original one-step process has been added to add a layer of code interception.
How to know whether an annotation is an annotation in the run-time or compile-time period is very simple. Click Ctrl+mouse and you will see:
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
Retention This enumeration type completely and clearly illustrates the period of the annotation you use.
Everyone likes to use singletons with spring, which is an excellent way. Singleton has nothing to do with concurrency itself, except that you have to make it compete for resource identification.
If you have to have many prototype objects in your project, it means that you abused or used the wrong object. MVC basically has incoming parameters and returns. Each request is a thread. A separate request response has what they enter and exit, which is completely isolated. From this, when it comes to mybatis, many people use various resmappers in mybatis configuration, and each time various beans go back and forth. After a request, the beans as parameters and results must be once. The surface of mybatis is clear to SQL maintenance, which is at the cost of greatly reducing the efficiency of jdbc. Then no one cares about it. For them, beans have nothing, and they don’t understand or care about gc. If they get problems, add memory and add memory to the top. All they solve is the problem of time, and use space to exchange time. With the same parameters and result mapping, then if you use jdk's map, which one is better, it is naturally jdk's own map.
I have always stubbornly believed that the consumption of new jdk's own object is much smaller than that of defining a bean by oneself. Why, Sorry, i do not know either. So I always come to map and map go. When using mybatis, you must closely detect whether your things are proxying to your class? The method is very simple. In the project log, open debug to see if your log is created a new sqlsession every time. If this is the case, you should note that your mybatis session is not pooled and not proxyed by things. If there is competitive SQL in a method, there is no error in Sorry, but it is found that the database does not execute your sql. Soon, you will find that the connection pool is used very quickly and will frequently create new connections. Of course, if you can do not use mybatis, don't hesitate, it is right not to use it.
Why do we have to try to use static annotations? It's very simple. Spring classes are basically singletons. The projects are large enough, and bean instances are enough. What do these singletons take up? The object instance is in the heap space and is referenced in the stack. So when will gc recycle objects from these singletons? what you think? Therefore, when based on annotation, try to minimize the use of dynamic proxy. Leave more resources for use where needed.
In the past, we would say that there is no heap, but now the string constant pool of jdk1.7 has already entered the heap.
Which is better, compilation type or interpretability? Of course, it is analytical, and compilation type is similar to the mediation model. Therefore, it is much more difficult to build an excellent compiled language than an interpreted language.
The structure of the web is very clear. First, it is still in the context, and then a series of components in sequence. The most important thing we are the servlet component, which is the Javaee standard, and the rest of the web components are protocol standards, which everyone must have. Then you will see that the mapping of servlets in many projects is /, which is a bad way. Because it is very simple, js or css never need to be processed through servlets. Therefore, mapping mainly considers interaction with the server components of web containers, and generally gives two types of identification, such as .do and .action .do requires permission authentication, etc., action is directly released. JS, etc. do not need to enter the servlet, and return directly from the web context according to the url, and then there is no way to intercept and release mvc into mvc. This is a waste of time to create problems and solve problems, which is not a good way. In this way, regardless of whether nginx is involved or not, your static resources are static for web containers and do not have any relationship with servlets. servlets only relate to what you need to handle.
Where is the best place to write js?
Many people are used to writing js in jsp or html, which is bad.
When we build a project, we must hope that our js and css will be cached by the browser.
Then, js written in the script tag of the page is just a tag, which is no different from div or input and will not be cached. I checked a lot of information, and the cache I saw obviously said that the cache unit is a file. Not the label. So I am not completely sure about writing your css js into the file and introducing the file so that the file will be cached, because there is no direct affirmative answer, it is my guess.
jsp is actually a servlet, so it is a dynamic page. Every time you need to load class to translate dynamically, and then the write method in the class writes the page to http to the browser and renders the browser. If it is html, it is static. Dynamic and flexible, there is no doubt that since it is a servlet, it is a Java object, and various Java tags and methods are called possibilities. Static pages need to be handled by yourself. If you use a macro language similar to static pages, it is better to use jsp directly.
How much data is loaded at a time on the page?
If the content displayed on your page is based on categories and lists, the amount of data is very small, with hundreds of items. The type is now displayed in the takeaway order app, then all categories and data are given at one time. Therefore, the processing is processed on the client side, the category switching and preview in the entire process are processed on the page, including search. The js executed on our client, A's mobile phone or computer will not compete with B's mobile phone or computer. If you switch a type every time you switch to a type, you will brush an ajax, and it is the same web container group, so that there will be competition. The more frequent the operation, the greater the competition. This is closely related to the actual scenario.
The amount of data returned by a query has nothing to do with performance. Thousands of thousands of data are only at the level of tens of KB.
The number of queries, that is, the number of interactions with the server, is the direct reason that affects the overall performance.
The amount of data in a query is proportional to the size of the table being queried. It will not speed up the query by returning 10 queries at a time, and 10 queries at a time, slowing down the query. The database operation is essentially a collection application and nothing is created.
The premise of tuning is that the amount given is the most appropriate, not the more you give, the more appropriate it is. The memory that jdk or tomcat can consume on different digits of Os.
Use nginx;
Use cache when necessary;
Select message middleware or other middleware according to whether you need to;
The separation of databases or master-slaves, etc. must be that the current database cannot support the traffic volume.
Singleton is a good way.
Multithreading is a sharp blade, and it does not distinguish between the specific language.
Maven management is a good way, but your project main body should be webmvc, build a web project, embed maven as a component, instead of creating a maven project and then converting it into a web project, unless it is idle.
Using spring, it is currently the best scaffolding.
Use jdbc as much as possible, if possible.
Don’t interact with the server when you can accomplish things on the client. The client’s resources are vast and the server’s resources are limited.
Try to send fewer requests. Codes that send fewer requests are good code, unless you are an instant application.
The tools in each code are tools, and the API is what you need to understand the most. There is no accurate answer to which one is better and which one is not good.
Everything is an object, and it is pure for Java. The proxy is an object, the reflection is an object, the object is an object, and the basic data type is not an object.
Things other than basic types are completed through objects. No matter how complex the process is, they are completed through the corresponding object methods combined with method parameters. How to serialize a class and deserialize it, to put it bluntly, it is the io and transmission of the file, and then load it into jvm and construct it into an object.
The reason why rpc is not called in a thread. The thing called is proxyed. The proxy converts your needs into parameters and sends them out as data streams. The server converts your request stream into objects and then streams them back. You then construct the object and process it through the object.
NIO is a good way, netty is a good choice, is there any multi-threaded socket that surpasses netty?
zookeeper is an excellent tool for a series of solutions such as good distributed registration.
These things are all principles and objects, so you need to use them to read them hard.
The above is personal understanding, and you are welcome to correct it.