Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the knowledge points of Java technology business scenario

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

What are the knowledge points of Java technology business scenario? I believe many inexperienced people are at a loss about this. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Overview of Spring

Spring is a completely interface-oriented design, reducing program coupling, mainly transaction control and the creation of bean instance objects. Acts as an adhesive in the integration of ssh. IOC (Inversion of Control) controls inversion / dependency injection, also known as DI (Dependency Injection) (dependency injection)

What IOC does: generate object instances, so it is based on the factory design pattern

Injection of Spring IOC

Injection through attributes, injection through constructors

Injection object array injects List collection

Inject Map collections inject Properties types

Spring IOC auto-binding mode:

You can set autowire to bind in the following ways

Press byType to find automatically as long as the type is consistent.

Press byName to automatically find and match by attribute name.

AOP aspect-oriented programming

AOP is a continuation of OOP, an acronym for Aspect Oriented Programming, which means aspect-oriented programming.

Note: OOP (Object-Oriented Programming) object-oriented programming

AOP is mainly used in logging, performance statistics, security control, transaction processing (used in projects) and so on.

Implement AOP technology in Spring:

AOP can be implemented through proxy mode in Spring

The agency mode is divided into

Static proxy: an interface with a real implementation and a proxy implementation, respectively.

Dynamic proxy: through the proxy of the proxy class, the interface and the implementation class can not be directly related, but can be dynamically associated at run time (Runtime).

There are two ways to implement dynamic proxy, either through the dynamic proxy of jdk or through cglib, while AOP is realized by default through the dynamic proxy of jdk. Jdk's dynamic proxy must have interface support, while cglib does not, it is class-based.

Description of the Spring AOP transaction:

In spring-common.xml, first set an expression to intercept transactions on those methods in service, such as add*, delete*,update*, and so on. We need to configure the transaction propagation (propagation= "REQUIRED") feature, usually other than add, delete, change operations need to be configured as read-only transactions (read-only= "true"). Read-only transactions can improve performance. After that, tx:advice is introduced, transactionManager (transaction management) is referenced in tx:advice, sessionFactory,sessionFactory is injected into dataSource in transaction management, and finally txAdvice is introduced.

Spring implements ioc control inversion description:

Originally, we needed to create and inject the bean ourselves, but now we leave it to the spring container to complete the bean creation and injection.

The so-called "control inversion" is the transfer of control of the object, from the program code itself to the external container.

Official explanation:

Control inversion is IoC (Inversion of Control), which transfers the call power of the object which is traditionally directly controlled by the program code to the container, and realizes the assembly and management of the object components through the container. The so-called concept of "control inversion" is the transfer of control over component objects, from the program code itself to the external container.

Transaction Overview √

In the database, the so-called transaction refers to a set of logical operation units, that is, a set of sql statements. When some of the operations in this unit fail, the entire transaction is rolled back and the commit is completed only if all are correct.

The ACID property of the transaction

1. Atomicity (Atomicity)

Atomicity means that a transaction is an indivisible unit of work, and either all or none of the operations in the transaction occur.

two。 Consistency (Consistency)

Transactions must transform the database from one consistency state to another. (data will not be corrupted)

3. Isolation (Isolation)

Transaction isolation means that the execution of one transaction cannot be disturbed by other transactions.

4. Persistence (Durability)

Persistence means that once a transaction is committed, its changes to the data in the database are permanent. Even if the system restarts, the data will not be lost; in JDBC, transactions commit automatically by default, and each time a SQL statement is executed, if executed successfully, it will be automatically committed to the database and cannot be rolled back

In order for multiple SQL statements to execute as one transaction:

(1) call the setAutoCommit (false) of the Connection object before executing the statement

To cancel the autocommit transaction

(2) after all SQL statements are executed successfully, call commit (); method to commit the transaction.

(3) when an exception occurs, call the rollback (); method to roll back the transaction.

Overview of permissions

Permissions involve 5 tables:

User table, role table, permissions table (menu table), user role association table, role permission association table

When the user logs in, verify whether the information is legal according to the user name and password in the user table, and obtain the user information if it is legal. Then, according to the user id, go to the user role association table to get the related role id set, then according to the role id, go to the role permission association table to get the permission id set, and then go to the permission id collection to get the specific menu in the permission table (menu table). Show it to the currently logged-in user, so that different users can see different menu permissions.

We use ZTree to empower characters and display menus through ZTree, and manage menus through ZTree, that is, add and edit menus.

We do the permission control to the url level, in order to prevent users from entering url access directly without logging in, intercept verification is carried out through the interceptor.

OSCache business scenario

In my previous project, we considered the problem of system performance. At this time, we used Oscache cache. At first, we gave this function to another colleague on the project team to do, but when he finished, he found that the cache had already cached data, but when he got it, he found that there was no data. Our project manager asked me to help take a look at this problem. After I read his code, he found that there was no data in the cache. I found that every time he caches, he calls a new cached object method, and as a result, there is a problem that he has already taken the cached method and can not get the data. Through my years of work experience, I thought that I should use singleton mode to encapsulate a singleton tool class to call oscache. However, in the later testing process, it is found that the above problems will also occur when concurrent access. At this time, I directly adopted the DCL (double decision Lock) singleton mode encapsulated the tool class, which not only solved the thread safety problem, but also considered the relative performance problem, and this problem was solved perfectly.

Overview of Thread

The state of a thread and the transition between states:

1. New state (New): a new thread object is created.

2. Ready state (Runnable): after the thread object is created, other threads call the object's start () method. The thread in this state is in the runnable thread pool and becomes runnable, waiting to gain access to the CPU.

3. Running: the thread in the ready state gets the CPU and executes the program code.

4. Blocking state (Blocked): blocking state means that the thread gives up the right to use CPU for some reason and stops running temporarily. You don't have a chance to go to the running state until the thread is in a ready state. There are three types of congestion:

(1) waiting blocking: the running thread executes the wait () method, and JVM puts the thread in the waiting pool.

(2) synchronization blocking: when the running thread acquires the synchronization lock of the object, if the synchronization lock is occupied by another thread, JVM will put the thread into the lock pool.

(3) other blocking: when a running thread executes the sleep () or join () method, or when an Icano request is issued, JVM puts the thread in a blocking state. When the sleep () state times out, the join () waits for the thread to terminate or times out, or when IBG O has finished processing, the thread returns to the ready state.

5. Dead: the thread ends its life cycle when it finishes execution or exits the run () method because of an exception.

There are two ways to implement threads:

Inherit the Thread class or implement the Runnable interface, but in any case, when the object is new, the thread has entered its initial state

The difference between wait and sleep:

Thread access:

Lock the pool state, wait for the lock to be released, and then access the code

Wait

Wait queue (release resources)-- > lock pool status after calling notify or notifyall-- > (wait for lock release)-> runnable status-> running status-> access code

Sleep,join

Do not release resources-- > enter the runnable state directly after the end-> running status-> access code

A java console program that runs two threads by default, a main thread and a garbage collection thread.

The difference between threads and processes:

1. Thread (Thread) and process (Process)

A process defines the boundary between an application and an application, and usually a process represents a corresponding application. Code and data space cannot be shared between different processes, while different threads of the same process can share code and data space.

two。 A process can include several threads, and multiple threads are created at the same time to complete a task, that is, multithreading.

Ajax request Session timeout problem

When I am working on a project, I sometimes encounter the problem of session timeout. If session times out, there is no problem with the usual request. You can jump to the landing page correctly through the interceptor, but if you request it with ajax, there will be a problem, because ajax is asynchronous and partially refreshed, so the login interface will no longer be displayed in the whole page, it will only be displayed in part of the page. So based on my experience over the past few years, I think I have found a better way. Because the framework I use is integrated with struts2, I set it in the interceptor:

First of all, to determine whether session is empty is to determine whether session times out. If it times out, it fetches the requested head header information request.getHeader ("x-requested-with"). If it is not empty, compare it with XMLHttpRequest (Ajax identity) (request.getHeader ("x-requested-with"). EqualsIgnoreCase ("XMLHttpRequest"). If equal, the request is an ajax request.

If it is an ajax request, you can use response.setHeader ("key", "value") to set an identity to tell the user that this is an ajax request and session timed out, so that I can take out the unique identity I set in the callback function: XMLHttpRequest.getResponseHeader ("). If the value taken out is the same as the value you set in the background, it proves that session has timed out, so you can set _ window.location.replace ("login interface") to jump to the login interface.

Although this solves the problem, the code will be written in each callback function, so the code will appear very fragmented, so I want to know if I can define a global setting, so I found the ajaxSetUp method of jqery. The ajax of jqery is judged globally by ajaxSetUp (ajaxSetUp is equivalent to the interceptor of ajax). By setting the complete in ajaxSetUp, it is equivalent to the callback function. In this way, that makes up for the deficiency of the previous method.

I also use $(document) .ajaxStart () when I do the project, which is the event of the ajax request; $(document) .ajaxSuccess (), which is the event after the AJAX request is successful. I usually use them to show the mask layer and hide the mask layer in order to prevent the user from repeatedly submitting, and to improve the user experience and let the user know that it has been submitted.

Overview of java thread pool

The working principle of java thread pool is similar to that of database connection pool, because each re-creation of a thread is a resource-consuming operation, so we can set up a thread pool so that when we need to use a thread to do something, we can go directly to the thread pool to find free threads, so that we can use them directly without having to wait for them to be created. After using it, you can put the thread back into the thread pool for other requests to use, thus improving the performance of the application.

The core process of the thread pool:

1. Build a ThreadPoolExecutor and specify the default number of threads to create

two。 Through threadPool.execute ()

To add threads to execute, that is, the java class that implements the Runable interface

3. Write the specific business code in the run method of the java class that implements the Runable interface

Business scenario of thread pool:

When I was working, a colleague gave me a request. At present, there are a large number of pictures that need to be processed with production thumbnails and watermarked, because it is too slow to process them one by one according to the ordinary processing method. I asked me if I had a good solution. At this time, I thought of the thread pool in java. I built a thread pool with 5 threads. Then the image information is extracted for a group of data by segmented batch extraction, and then these are handed over to the threads in the thread pool through the execute method of Threadpool, that is, making full use of CPU hardware resources and speeding up the processing efficiency of the program in the case of big data.

At that time, in the course of my work, I knew a friend who was an e-commerce business. at that time, their company had just started, and many of their technologies were not mature, so they often discussed some technical problems with me. Once he asked me a question. He asked me how to improve the performance of the website. I gave him a lot of suggestions based on my experience in the project and the materials I had read about optimization. Such as full-text search with lucene, distributed cache with memcached, and static pages generated by spring timer combined with freeMarker template engine, as the number of pages to be generated is relatively large, taking into account the performance of the program, I suggest that he work with java thread pool, so that you can make full use of CPU hardware resources and speed up the processing efficiency of the program in the case of big data.

If you're still a little confused, join my Java architect: 766529531 and talk to senior engineers with many years of Java development experience. You can also get free video learning materials and e-book learning materials!

Overview of OSCache

Oscache is a high-performance j2ee framework that can be integrated with any java code, as well as caching page content through tags and caching requests. We usually cache data that is accessed frequently but does not change often. In order to ensure the validity of the cached data, when the data changes, we should refresh the cache to avoid the emergence of dirty data. There are two strategies to refresh the cache, one is regular refresh, and the other is manual refresh. The timing of caching data is usually divided into two types, namely, loading data for caching when tomcat (web container) starts, and caching when users access the data for the first time, which is equivalent to immediate loading and on-demand loading of the cache.

The level of cache is as follows: jsp-- > action-- > service-- > dao. The more advanced the cache, the greater the performance improvement. There can be multiple service in an action and multiple dao or service in a service. Any class can call each other, and the related classes can be connected by passing parameters of constructor, passing parameters of set,get or passing parameters of methods.

OSCache+autocomplete+ singleton business scenario

When I was working on a project, in order to improve the user's experience when querying the product list, we used the autocomplete plug-in instead of select to select the brand. At the beginning, we had to query the database according to the information entered by the user for fuzzy matching and return the results. Later, we considered the performance of the system, so we adopted oscache cache. At first, this function was given to another colleague on our project team, but after he finished, when we used this tool class, we found that sometimes the data we needed in the cache was already in the cache, but when we took it from the cache, we found that we didn't have it. Then the project manager asked me to take a look at this problem for this colleague. After reading his code, I found that it was using cache in it. A new instance is generated for each method call, which leads to the above problem. At this time, I remembered that I could use the singleton pattern in the design pattern to solve this problem. At first, I directly adopted the ordinary single-column pattern. But later, in the course of testing, I found that the above problem still occurred when the user concurrency was large, and then I reconsidered the code. Finally, it was found that it was because there was no lock on the single-column mode, which led to the problem of thread safety when large users were concurrent. Then I added the synchronized keyword to the method to solve the above problem, but later the testers reported that there was a problem with the performance of this section. After considering it, I solved the above problem by adding a lock in the method body and combining double judgment. We load the data into the cache when tomcat starts, and then get the data directly from the cache when users query, query according to prefix matching, and return the results to the user. This not only improves the user experience, but also improves the performance.

Overview of caching

Applications can use caching to improve performance. Cached storage media can be stored in memory or hard disk, and data is usually stored in memory, specifically in jvm memory. Caching is based on the idea of Map and is accessed in the way of key-value pairs. The reason why the cached data can be stored on the hard disk is that memory resources are quite limited and valuable. Therefore, when the memory resources are insufficient, it can be stored in the hard disk. Although the access speed of the hard disk is slower than the memory, it still improves the performance of the program because of the reduction of network traffic. Caching can be divided into client-side cache and server-side cache, the so-called client-side cache usually refers to the cache of IE browsers, and server-side cache refers to the cache of web server, which can usually be implemented through third-party components, such as oscache,memcache

We usually cache data that is accessed frequently but does not change often. In order to ensure the validity of the cached data, when the data changes, we should refresh the cache to avoid the emergence of dirty data. There are two strategies to refresh the cache, one is regular refresh, and the other is manual refresh.

The level of cache is as follows: jsp-- > action-- > service (usually placed in service)-> dao. The higher the cache, the greater the performance improvement.

Cache strategy: (used when cache space is insufficient and needs to be cleaned)

LRU: the principle of least recent use. (understanding: storing books)

FIFO: first-in, first-out caching strategy. (understanding: queuing)

Can you tell me about caching? Tell me about your understanding of caching (if you encounter repetition, you can omit it)

The purpose of using caching in the project is to improve the performance of the application, reduce the number of times to access the database, and thus improve the throughput of the application. We usually cache permissions, menus, organizations, which are frequently accessed but do not often change, among which I cached the ZTree tree menu through oscache when I was doing () a certain project, and combined with the single-column design pattern when doing it, considering the security problems under multi-threading, and added a double lock check method to the singleton mode.

Realize the static business scenario of the page

When we are working on a project, it involves the performance of program access, so we think that we can improve the performance of user access through static, so we use the freemarker template engine. Considering that the page also needs to change dynamically, we use the spring timer to generate the html static page again at 2 o'clock every night, considering the performance problem at the time of release. We also adopt thread pool technology to let multiple threads publish at the same time, so as to reduce the release time.

Servlet thread safety description

Servlet is single-column and uses one instance for all requests, so thread-safety problems can occur if global variables are used by multiple threads.

There are three solutions to this problem:

1. Implement the singleThreadModel interface so that a new servlet instance is created for each request, which consumes server memory and degrades performance, but this interface is outdated and is not recommended.

two。 Thread safety issues can be avoided by locking (the synchroniezd keyword). At this time, although it is still a single column, but for multi-threaded access, only one request can be executed in the method body at a time, and only after the execution is completed, other threads are allowed to access, reducing throughput.

3. Avoid the use of global variables, the use of local variables can avoid thread safety problems, this method is highly recommended to solve servlet thread safety problems.

(jbpm4) Workflow engine description:

JPBM is an open source hibernate-based workflow engine under JBOSS. Workflow is in daily life, some of our common processes, such as leave process, procurement process, induction process, popularly speaking, some of the processes in real life are realized in an information-based way.

A workflow first needs a process definition, which is composed of nodes and jumps, which can also be called links, activity nodes and activity links, and nodes can also be divided into two types: artificial nodes and automatic nodes. Artificial nodes have start start nodes, end end nodes, task task nodes, and automatic nodes have decision judgment nodes, fork branch nodes, join aggregation nodes and state state nodes. And a process has one and only one start node, but can have multiple end nodes.

The process definition is static, it will be transformed into a process instance when it is running, and a process definition can correspond to multiple process instances. After the process runs, it will generate two files, * .jdpl.xml file and * .png image file, as well as 18 database tables. The common and core tables are JBPM4_LOB storage tables, which mainly store xml files and png images, JBPM4_TASK task table, JBPM4_EXECUTION process instance table and JBPM4_VARIABLE variable table.

Graphical flexible customization (active speaking)

The flowchart can be changed according to the requirements, that is, the defined flowchart can be changed as needed, not dead.

Graphical monitoring can be carried out (active speaking)

Output picture

Get the coordinates of the active node

Superimpose

Judge node: (take the initiative, you can also understand)

Implement the implements DecisionHandler interface and override the decide method

The returned string should be consistent with the name of the transition configured in xml.

Branch decision node

JBPM has five core classes:

ProcessEngine: mainly get all kinds of Service

RepositoryService: main release process definition

ExecutionService: main operation process example

TaskService: mainly operate human services

HistoryService: the main operation history service.

Core method:

Read the file defined by jbpm to generate the zip package and save it to the lob table: createDeployment ()

Get process definition list: createProcessDefinitionQuery

Start the process instance based on the defined key or id: startProcessInstanceByKey (id)

Get to-do list: findPersonalTasks (userName)

Complete the assigned task list: completeTask (* .getActivityId ())

Get the list of historical tasks: createHistoryTaskQuery ()

Get the ID:task.getExecutionId of the process instance ()

(table of understanding)

JBPM4_HIST_ACTINST process activity (Node) instance Table

Details of JBPM4_HIST_DETAIL process history

JBPM4_HIST_PROCINST process instance history table

JBPM4_HIST_TASK process task instance history table

JBPM4_HIST_VAR process variables (context) history table

JPBM business scenario

First of all, we define the process of asking for leave. The definition of our process is (the employee submits the request for leave-- "Manager approval -" Director approval-"General Manager approval -" ends), and publishes it to the jbpm4_lob table through repositoryService.

After obtaining the process definition list, selecting the process definition for leave, the employee begins to fill out the leave request, saves and opens the process instance through executionService, then uses taskService to obtain the manager's to-do list, selects the to-do task, carries on the approval, enters the approval link of the director by calling taskService.completeTask (), then logs in with the director, and also obtains the to-do list. Then call taskService.completeTask () to enter the general manager approval link, after the general manager approval, the end of the process. In the process, we can also view the list of tasks that have been done by the current login according to historyService.

Ant description

Ant is apache's build tool for automatically packaging, compiling and deploying projects. It is mainly lightweight and cross-platform, and is based on jvm. The default file name is build.xml.

The main tags of Ant:

Project root tags, target task tags, property attribute tags, custom keys / values for multiple uses, java executes compiled java files, javac compiles java files, war into war packages, other tags: copy,delete,mkdir,move,echo, etc.

FreeMarker description

FreeMarker is a template engine written in Java language. It is a general tool for generating text output based on templates. Freemarker can generate a variety of text outputs such as HTML, XML,JSP or Java.

How it works: define template files, embed data sources, and display prepared data through templates

(data + template = output)

In using the template, we find that freemarker has many advantages. It completely separates the presentation layer from the business logic. The template is only responsible for the performance of the data on the page and does not involve any logical code, so it makes the division of labor in the development process more clear. As an interface developer, you only need to concentrate on creating HTML files, images and other visualization aspects of the Web page, regardless of the data. On the other hand, the program developer focuses on the system implementation and is responsible for preparing the data to be displayed for the page.

If you use jsp to show, the development phase to adjust the function at the right time, need to frequently modify the JSP, each modification has to compile and convert, wasting a lot of time, FreeMarker template technology does not have the problem of compilation and conversion, in the development process, we do not have to wait for the interface designer to complete the page prototype before developing the program. As a result, the use of freemarker can also greatly improve development efficiency.

WebService description

(speaking on his own initiative)

Webservice is an implementation of SOA (Service oriented programming), which is mainly used to realize the communication between heterogeneous platforms, that is, the data transmission between different projects on different platforms, so as to avoid the problem of information isolated island. The reason why it can communicate on heterogeneous platforms is because it is completely based on xml, so webService is cross-platform, cross-language and cross-framework. In java, there are usually three technical frameworks are xfire,cxf,axis2.

We're trying to make sure

The security of webservice, based on the

Security verification of the WS-Security standard (using callback functions).

(there is no need to take the initiative)

The three elements of webservice are:

Wsdl (webservice description language) is used to describe published interfaces (services)

Soap (simple object access protocol) is the combination of xml and http, and it is the protocol of webservice data communication.

Uddi is used to manage and query webService services.

(there is no need to take the initiative)

The specific three implementation ways of webservice (framework) or the difference between the three implementation frameworks

1. Axis2: can be developed in multiple languages, is a heavyweight framework, very powerful, but its performance is relatively low.

2. Xfire: it is a lightweight framework compared to Axis2, and its performance is higher than that of Axis2.

3. Cxf: an upgraded version of Xfire, just like struts2 is an upgrade of webwork, and then cxf and spring are very convenient and easy to integrate, and their performance is higher than that of Xfire.

[note] webservice jws that comes with jdk6

(speaking on his own initiative)

Business scenario

When I was working on a project in the past, I encountered a function that needed to transfer data between two projects. The project manager asked me to complete this task. Based on my previous project experience, I thought of two solutions. The first is to open the permissions of the database of another project to me, and then I directly access the database of another project to get the information I need, but then I analyze it. I felt that this way was not safe, and because another company was responsible for the project at that time, the table structure in the database

And later involved.

There are many responsibility problems, so I adopted the second scheme, that is, to transfer data and information between heterogeneous systems through webservices. The specific implementation of webservices is xfire,cxf,axis2. According to my previous project experience, I understand that cxf is an upgraded version of xfire, which is suitable for java language. Xfire/cxf has higher performance than axis2, and it is more convenient to integrate with spring, while axis2 supports more languages. The performance is low compared to cxf, through the above analysis, combined with our current two projects are based on java language, so I use cxf to achieve the data transfer between the two projects, in order to ensure the security of webservice, we use security verification based on WS-Security standard (using CXF callback function).

(there is no need to take the initiative)

Webservice server configuration process

First, we introduce the cxfServlet core class into web.xml, specifying that webservice services are provided for the url path that starts with / cxf. Then we add @ Webservice annotation to the webservice interface to be published, and we also add the same webservice annotation to the implementation class and specify which interface is implemented. Then we publish the webservice service in spring-webservice.xml, using the jaxws:endpoint tag, and configure implementor and address on the tag to indicate the class that implements the service. And the address of the release, and finally enter the relevant webservice address-wsdl in the browser to verify whether the service has been published successfully.

(there is no need to take the initiative)

Configuration of webservice client

First of all, the intermediate bridge java class called by the client is generated through wsdl2java according to the wsdl of the published webservice server address, the generated java class is copied to the client project, the configuration spring-client.xml file is configured, a bean is defined through jaxws:client, and the service address of the webservice to be accessed is indicated through the address attribute, and the service class acting as the intermediate bridge is indicated by serviceClass, and then the bean is obtained, and the method in the published webservice interface can be accessed through it.

Overview of oracle Index

Index is an optional structure related to tables, which can improve the retrieval efficiency of sql statements, which is equivalent to our dictionary directory and can be located quickly. So we can reduce the disk Ibank O, but because the index is physically and logically independent of table data, it will take up a certain amount of physical space (extra disk space), so it is not that the more indexes the better, but we should create indexes according to business requirements, and oracle has to maintain indexes automatically when adding, deleting and modifying operations, so it also reduces the maintenance speed to a certain extent. Moreover, it takes time for us to create and maintain the index, which increases with the increase of the amount of data. generally, we create the index by creating the create index index name on table name (field). The index is divided into ordinary index unique index (unique) single index composite index (also known as composite index, which can contain multiple field names in the index building statement), sequential index. Hash index, bitmap index.

Oracle stored procedure

A stored procedure encapsulates a collection of sql, that is, a set of sql statements. The advantage of the procedure is that it simplifies the sql command and is precompiled, so it has high execution efficiency and performance. moreover, if you do not call the procedure, you have to interact with the database many times, and the calling process only needs to send a command that all the execution logic is executed on the database side, so it reduces the traffic of the network. Second, stored procedures greatly improve security, which is the advantage

The disadvantage is that different databases support different keywords for process support, so its portability is very poor. Moreover, its maintainability is relatively difficult, because it does not have professional debugging and maintenance tools, so it is more troublesome to maintain. This is the basic overview of stored procedures.

Junit business scenario

When we develop a project, in order to improve the performance of the code and ensure the logical correctness, we often have to carry out unit tests to verify the code after we write the code. at that time, all developers in our company use the main method for verification, but the biggest disadvantage of using mian is that multiple classes cannot be verified at the same time. The verification result is not intuitive and the test is complex (each class has to write the main method and run it individually). To some extent, the project manager and I proposed to use Junit, a professional testing tool, to test, because Junit is a unit testing framework in Java language, which is simple to test, which can not only provide work efficiency and code quality, but also improve the team's ability to cooperate. I propose that after we conduct Junit training, we use Junit4 plus annotations to test.

Implementation of load balancing and seesion replication by Apache+Tomcat

When we have a large number of tomcat visits and not enough thread connections, we consider the load balancing of tomcat to share too much access. In terms of performance, load balancing can also use multiple tomcat to increase the amount of memory.

Process, prepare to work apache,Jk_mod,tomcat, introduce a custom mood_jl.conf in the conf/httpd.conf file of apache using the include tag, introduce the downloaded k_mod-apache-X.X.XX.so file in modules, introduce our .so, and work.properties files, and specify the load distribution controller controller, and worker.list=controller,tomcat1,tomcat2 specify the service,worker.tomcat1.port Ajp port number in the work.properties file Type is the ajp,host that specifies the allocation weight value for the specified ip,lbfactor, the greater the distribution weight value, the more sharing requests. The worker.controller.type=lbworker.controller.balanced_workers=tomcat1,tomcat2 specifies the replication of the tomcat Session of the sharing request. In the tomcat, the Engine tag adds the tomcat name specified in the jvmRoute value to work,properties, and then opens the custom folder name-- > META-INF-- > servies.xml.

3. Configure name of service and corresponding springBeanName in servies.xml

4. Enter the server address of webservice in the browser and add? wsdl to test to see if the release is successful.

Axis2 client configuration proc

1. Generate client code based on the url of the webservice server through wsdl2java

two。 Introduce the code into the project folder for normal access

26, spring timer

Execute at regular intervals

1. Create a collection of triggers triggers

two。 Establish a SimpleTriggerBean and specify the time between each time and the number of times to execute and the target to be executed

3. Find the concrete method of the concrete class to be executed through targetObject and targetMethod, and the target object is a common java class.

Execute at a specified time

1. Create a collection of triggers triggers.

two。 Create a CronTriggerBean to specify the cron expression and the target to execute

3. Find the concrete method of the concrete class to be executed through targetObject and targetMethod, and the target object is a common java class.

Overview of Ext

As far as I know, Ext is a RIA framework written in js, which can be used in combination with various background languages. The module I completed with Ext in the project looks like this. First of all, I layout it in such a way that layout equals border, which is divided into top and bottom, left and right, then displays the menu with exttree on the left, then adds tabs through tabs in the middle area, and in the tabs are grid and form one by one, in which I am doing grid. First, access the data set in model format returned by the background through store. Store interacts with the background contoller through proxy, and then assigns store to the store attribute of grid and renders it in the specified location through renderTO.

Grid question:

When I was doing grid at that time, I found that the data was not displayed. I tracked it through F12 and found that no request was sent at all. Later, I analyzed it and found that this problem was caused because the loadPage method of store was not called. In addition, in the process of doing the project, a person under my hand is also in charge of grid, the data can be displayed normally, but the paging information is not displayed. By tracking his code, it is found that he did not assign the store attribute to the paging toolbar, which led to this problem.

Tabs tab:

When I was working on the module of tab tabs, I first created a tab page with TabPanel when loading the page and let it be displayed in the middle. Then I clicked on the left Tree menu to call the add method to dynamically add tab tabs, but there was a problem that the same tabs would be added repeatedly in the process. I checked some relevant information. Finally, determine whether the tab is selected by the id of the tab or a unique identifier. If so, call setActiveTab to activate the tab and let it be selected, otherwise a tab will be added. Finally, it achieves the effect that tab is added when it does not exist, and it is selected if it exists.

Learn about:

Ext4.0 also supports the front-end MVC development model:

Why not adopt the development mode of mvc?

At that time, due to time reasons, the project manager decided to use this common development model for development, and did not adopt the mvc model of Ext4.0. But I think their core operating procedures are the same, so it's not difficult for me to learn and use this way.

Overview of lucene

Lucene is a full-text search engine, it can be used to replace the like in the database when fuzzy matching, so that the matching accuracy and performance can be greatly improved. When I am working on the XX module of the XX project, I use lucene for full-text search and IK word participle for word segmentation. Thus, it realizes the high-performance search of highlighting keywords, paging, sorting, multi-fields and multi-conditions. When fetching data from the data to generate the index, because the amount of data in the table is relatively large, which prevents the memory overflow caused by one retrieval, I use the method of segmented batch extraction. In addition, we adopt different strategies for the subsequent added data according to the priority. For those data that need to be displayed in time, we use spring timer to generate the incremental index in a short time (30 minutes). For those data that do not need to be displayed in time, we use the spring timer to regenerate the index in the early hours of the morning every night.

Thread pool function

1. Reduces the number of threads created and destroyed, and each thread can be reused to perform multiple tasks.

two。 The number of threads in the thread pool can be adjusted according to the bearing capacity of the system to prevent server downtime due to excessive memory consumption (each thread needs about 1MB memory, and the more threads open, the more memory consumed, and finally downtime). Usually the thread pool we use is ThreadPoolExecutor that implements ExecutorService.

How jbpm integrates with spring

1. Configure springHelper in the spring-common.xml configuration file, create processEngine through springHelper, and obtain the Service of various workflows through processEngine, such as repositoryService,executionService,historyService,taskService

two。 Create a new jbpm.cfg.xml file under the src root directory

Tomcat optimization

Increase memory (heap, persistent generation) and turn on server mode

When I was doing the XXX project, I used poi to import and export data, because the company's business is relatively numerous, the amount of data is very large, the test times memory overflow, after my analysis combined with online access to information, found that tomcat memory may be insufficient, need to be increased, modify the configuration file after the test no longer error.

Tomcat increases memory by modifying the tomcat configuration file

Under window, add the following at the beginning of the bin/catalina.bat file:

Set JAVA_OPTS=-XX:PermSize=64M-XX:MaxPermSize=128m-Xms1024m-Xmx1024m

Under linux, add the following to the front of catalina.sh:

JAVA_OPTS= "- XX:PermSize=64M-XX:MaxPermSize=128m-Xms1024m-Xmx1024m"

-client-service

When we run-java in cmd, the two parameters-client-service appear in the black window. Its function is to set the virtual machine running mode; client mode starts faster, but runtime performance and memory management efficiency is not as efficient as server mode, and is usually used in client applications. Server mode starts more slowly than client, but achieves higher performance. Windows defaults to client. If you want to use server mode, you need to add the-server parameter when starting the virtual machine to achieve higher performance. For server-side applications, server mode is recommended, especially for systems with multiple CPU. On Linux,Solaris, the default value is server mode.

JDK version

There are also JDK versions that affect virtual machines. JDK is divided into 32-bit and 64-bit versions. 32-bit systems are installed on 32-bit systems. 64-bit systems can install 32-bit and 64-bit JDK.64-bit JDK with better performance than 32-bit JDK.

The tested command java-xmx value m-version failed to report the wrong configuration size, and vice versa

Increase the maximum number of Tomcat connections

Working with scen

After I finished a XXX project, I found that when the number of concurrency increased to a certain extent, it would be very stuck, so I wondered if there was a limit on the maximum number of connections in tomcat. Sure enough, the maximum value in the configuration file was only 500, so I changed the maximum number of connections. According to the business, I modified the number of connections to 2000, which solved the problem perfectly.

Modify the default value of the method in conf/service.xml

, just change the value of maxthreads

Tomcat carries out gzip compression to reduce network transmission.

Tomcat Compression Settings tomcat Compression gzip enabled

HTTP compression can greatly improve the speed of browsing the website. its principle is that after the client requests the corresponding resources from the server, the resource files are compressed from the server and then output to the client, and the browser of the client is responsible for decompressing and browsing. Compared with the normal browsing process HTML, CSS,Javascript, Text, it can save about 60% of the traffic. More importantly, it can compress dynamically generated web pages, including CGI, PHP, JSP, ASP, Servlet,SHTML and so on, with high compression efficiency.

Enable gzip compression for tomcat

To use gzip compression, you need to add the following attributes to the Connector node

Compression= "on" turns on compression

CompressionMinSize= "50" enables compressed output content size. Default is 2KB.

NoCompressionUserAgents= "gozilla, traviata" does not enable compression for the following browsers

Which resource types of compressableMimeType= "text/html,text/xml,text/javascript,text/css,text/plain" need to be compressed

Introduction of memcached

Memcached is a distributed cache developed in C language, internally based on a hashMap-like structure. Its advantages are simple protocol, built-in memory storage, and its distributed algorithm is completed on the client side and does not need to communicate on the server side. When we were working on the project, we adopted the load balancing method of apache+jk+tomcat in server deployment because of the high availability and high scalability of the project, but it also brought a problem, that is, the problem of session sharing. Although this problem can be solved by session replication, there are performance defects, so in the end, we use memcached to store session, which solves both the session sharing problem and the performance problem caused by session replication.

Understand (you don't have to say it on your own initiative, but you must know if others ask)

Memcached stores data in the way of KEY-VALUE. Size limit of KEY: Key (max)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report