JAVAEE project structure and concurrent thoughts

  • 2020-05-10 18:04:50
  • OfStack

      has long dominated scaffolding in the javaee field led by spring   struts2 mybatis/hibernate;

Spring:

Spring is not just for Java services The implementation of spring as the cgi standard is not just a framework for the Java domain. The C# platform can still benefit. spring provides various convenient annotation configuration methods such as abstraction or bootde 1 embodiment scheme, which greatly simplifies the project basis of Javaee.

In the use of spring, the two-sided split, part 1, lightweight annotations, part 1 tends to be full annotations.

The premise of the first annotation is that it is necessary to experience the proxy, dynamic, static, cglib proxy. For lightweight annotations, the Angle stands at the static or first order annotation,

For example, controller annotations, these one-pass annotations or compile-time annotations, are initialized in the project context as an implicit one-pass scan. Related annotations include service and similar annotations, which provide singleton lightweight object instances. As preferred. This reduces the need for run-time proxies, reflections, which can be very disruptive, and also saves better resources on the run-time stack.

Another class, such as responsebody, is a dynamic or runtime annotation whose reflection is executed on each request. Runtime annotations, of course, are resource hogs.

In general, it is not necessary annotations can not completely annotations, based on the servlet request, no problem too mvc response way, take ginseng, ginseng, returns, etc., has no need of runtime annotations, runtime comments seemed to reduce the amount of code, in order to make in the process of all kinds of deficiency, will run a circle of the dynamic annotation to perform one was inside the method you use annotations. What code is missing from the param annotation written in the method compared to the request get   annotation? But let the original 1 step in place of the processing, added a layer of code interception.

How to know if an annotation is a run-time or compile-time annotation is simple. Ctrl+ mouse click and you will see:

@Target({ElementType.TYPE, ElementType.METHOD})

@Retention(RetentionPolicy.RUNTIME)

@Documented

The enumeration type Retention   fully and clearly states the duration of the annotation you are using.

With spring everyone loves singletons, which is a great way to do it, singletons have nothing to do with concurrency per se, except you have to make it a resource identification competition,

If you have to have a lot of prototype objects in your project, then you are abusing or using the wrong object. mvc is basically an input and a return, and each request is a thread, and a separate request, response,   has everything they go in and out of, completely isolated. Said to mybatis from this, many people use mybatis1 configuration of various resmapper inside, every time is various bean walking back and forth, a request, as a result of the parameters and bean must be 1, above clear sql mybatis surface maintenance, is heavily down jdbc efficiency at the expense of, then didn't have a lot of people care about, bean for them, have no what, don't know nor care gc, add memory problems, memory to add to, is only a matter of time, to solve the trading space for time. If the same parameter is mapped to the result, then new 1 bean   USES jdk's map, which is better, jdk's map naturally.

Personally, I have always insisted that new1 jdk object by itself is much less expensive than defining 1 bean. Why? Sorry, i   do not   know either. So I've always been map to come and map to go. If you use mybatis, 1, you must closely detect whether your things have been proxy to your class. The method is very simple. In the log of the project, open debug, and check whether your log is create a   new sqlsession. There are no errors in one method if there is a competitive sql, sorry  , but it is found that the database did not execute your sql. Soon, you will find that connection pooling is used quickly and new connection will be created frequently. Of course, if you can do without mybatis, don't hesitate, it's right not to.

Why should 1 use static annotations as much as possible? It's very simple. spring classes are mostly singleton, and the project is big enough, and bean instances are big enough. Object instances are in the heap space and references are in the stack. So when will gc recycle these singletons? What do you think? Therefore, minimize the use of dynamic proxies based on annotations. Leave more resources for where they are needed.

We used to say no heap, no stack, but now we're going to change the jdk 1.7 constant pool of string into the heap.

Which is better, compiled or interpreted, is of course analytic, and compiled is similar to the mediation model. Therefore, building a good compiled language is much more difficult than an interpreted language.

The structure of web is very clear, first is the context again, then is the sequence of 1 series components, our most key is the servlet component, this is the standard of javaee, the rest of web components is the protocol standard, everyone must have. You will see many servlet mapping is/project, this is a bad way, because it is very simple, js or css never necessary to handle by servlet, therefore mapping mainly considering the server-side component interaction with web containers, 1 to two kinds of identification, such as. do and. action  . do need permission certification, action belongs to direct release. js and others do not need to enter servlet, but directly return according to url in the context of web, and then do not add 1 mvc's interception and release to mvc. This is not a good way to create and solve problems. This way, with or without the intervention of nginx, your static resources are static to the web container, not related to servlet. servlet is only about what you need it to handle.

Where should I write js?

A lot of people are used to writing js in jsp or html, which is terrible.

When we build a project, we must want our js and css to be 1 and must be able to be cached by the browser.

So js in the script tag on the page, js is just a tag, no different from div or input, it won't be cached, I looked up a lot of information, and I saw that the cache, obviously it says, the unit of the cache is the file. Not the label. So put your css   js in the file, bring in the file, so the file will be cached, and this point, I'm not entirely sure, because there's no direct positive answer, it's my guess.

jsp is actually servlet, so it is a dynamic page, and every time it needs to load class to dynamically translate, then write method in class writes the page to http and renders it to the browser. If it is html, it is static. Dynamic flexibility, this is no doubt, since it is servlet, then it is java objects, various Java labels and methods are called possible. Static pages need to be handled by yourself. Use a similar macro language for static pages instead of jsp.

On the page, how much data is good to load once?

If your pages to show things by category, according to the list, very little data volume, hundreds of types of selling point meal app display outside now, so, once given all classification with data, so the processing on the client side processing, the category in the process of switching, preview, all the page to deal with, including search, our client js,   A inside the mobile phone or computer to execute js won't compete with B mobile phone or computer, If you swipe 1 ajax every time you switch 1 type, you are competing with 1 web container group. 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 little to do with performance, and thousands or tens of thousands of pieces of data are just a few levels of 10KB.

The number of queries, that is, the number of interactions to the server, is the direct cause of overall performance.

The amount of data in a query is directly proportional to the size of the table being queried. The query will not be slowed down because 10 pieces of data are returned once and 1W pieces are returned once. The database operation is essentially a collection application without creating anything.

The premise of tuning is to give the most appropriate amount, not more. The amount of memory that jdk or tomcat can consume on different bits of os is capped.

Use nginx;

Use caching when necessary;

Select message-oriented middleware or other middleware according to the need;

Database separation or master from, 1 must be the current database can not support the volume of business.

Singletons are good.

Multithreading is the sharp edge, does not distinguish which specific language.

maven management is a good way, but your project body should be webmvc, build web projects, embed maven as a component, rather than build an maven project and then convert to web projects, unless it is idle.

Using spring is currently the best scaffolding available.

Use jdbc whenever possible, if possible.

What can be done on the client side, do not interact with the server side. The client side's resources are vast and the server side's resources are limited.

Make as few requests as possible. Code that makes as few requests as possible is good code, unless it's your immediate application.

Every tool in the code is a tool, API is what you need to understand most, which is good, which is bad, there is no exact answer.

All objects are pure to Java, proxy is object, reflection is object, object is object, basic data type is not object.

Everything except the basic types is done by objects, no matter how complex the flow is, by combining the methods of the corresponding objects with the parameters of the methods. How to serialize an class, how to deserialize it, basically, is the io file with the transfer, and then load it into jvm, and construct it into an object.

The reason why rpc rpc is not calling something in a thread, it's calling something, it's being proxied, it's being proxied, it's being proxied, it's being proxied, it's being proxied, it's being proxied, it's being proxied, it's being proxied, it's being proxied, it's being proxied, it's being proxied, it's being proxied, it's being proxied, it's being proxied, it's being proxied, it's being proxied, it's being proxied, it's being proxied.

NIO is a good way, netty is a good choice, multithreaded socket has surpassed netty?

zookeeper is an excellent tool for good distributed registration and other 1 series solutions.

These things are principles plus objects, with which you have to look hard.

Above is personal understanding, welcome to correct.


Related articles: