Java-web Review Stage 2

Source: Internet
Author: User
Tags repetition

11, File Upload ~ ~ ~
Apache offers Commons-fileupload
Smartupload
Struts2 File Upload
Step One: Form forms use post submission, and the form adds enctype= "Multipart/form-data",
Implement multimedia encapsulation.
Form items <input type= "file" Name= "MyFile" >,file form items must have the Name property, otherwise they will not be uploaded.
Step Two: Develop the program to process the file upload data.
You can use Apache to provide commons-fileupload to complete file uploads.
2, the location of the file save
3. Prevent uploading of files with duplicate name overlay
4. Prevent excessive uploading of files in the same directory


12, paging (with query conditions) ~ ~ ~

13. Business

The four characteristics of the transaction ~
The four characteristics of a transaction are the characteristics of the transaction itself. referred to as acid.
Atomicity (atomicity)
Atomicity means that a transaction is an inseparable unit of work, and the operations in the transaction either occur or do not occur.
Consistency (consistency)
The integrity of the data before and after the transaction must be consistent.

Isolation (Isolation)

The isolation of a transaction is that when multiple users access the database concurrently, the transaction of one user cannot be interfered by another user's firm.
Data between multiple concurrent transactions is isolated from one another.

Persistence (Durability)
Persistence refers to the fact that once a transaction is committed, it changes the data in the database to be "permanent".
Next, you should not have any impact on the database if it fails.

Four Isolation Levels ~
So what should database designers do to prevent problems when designing a database? The more problems you prevent, the lower the performance,
The less problems you prevent, the worse your security is.
In the end, the database user should not be able to decide which problems should be determined by the database users according to the specific business scenario.
Instead of writing down what kind of problem you put in, you provide the following options:
Four isolation levels of the database:
READ UNCOMMITTED;
---do not make any isolation, may cause dirty read non-repetition degree of virtual reading (phantom reading) problem
Read Committed;
--prevents dirty reads, but does not prevent non-repeatable read (phantom reading) problems
REPEATABLE Read;
--can prevent the dirty read non-repetition, but does not prevent the virtual reading (phantom reading) problem
Serializable
--can prevent all isolation problems, but the database is designed to be serialized database, performance is very low
From the security considerations:
Serializable > Repeatable Read > Read Committed > READ UNCOMMITTED
From the performance considerations:
READ UNCOMMITTED > Read committed > Repeatable read > Serializable

Locks in the database:
1.8.1. Shared locks
Shared and shared locks can coexist, and shared and exclusive locks cannot coexist.
Do not add any locks at the non-serializable isolation level.
Query plus shared locks are made under the Serializable isolation level.

1.8.2. Exclusive locks
Exclusive and shared locks cannot coexist, and exclusive and exclusive locks do not coexist, and additions and deletions are added to the exclusive lock at any isolation level.
1.8.3. Possible deadlocks
MySQL can automatically detect a deadlock, the error exits one party executes the other party

1.9 Update lost Problem ~ ~ ~

1.9.1. The generation of update loss issues
Two concurrent transactions are modified based on the same query result.
Subsequent transactions ignore the impact of the first committed transaction on the database, resulting in the loss of the impact of the first committed transaction on the database.
This process is called update loss.

Optimistic and pessimistic locks are not the real locks in the database, but the names of the two solutions.
(1) Pessimistic lock: Pessimistic thinking that every modification, will operate update lost issues.
At query time, a manual exclusive lock is added to exclude possible updates from being lost at query time.
SELECT * from the users for update;
(2) Optimistic Lock:
The design version field in the table, when modified, requires modifications based on the specific version, and the Version field +1,
If the update fails, the update is missing and needs to be updated again.

#两种解决方案各有优缺点:
If the query is much less modified, use optimistic locking.
If you modify multiple queries less, use pessimistic locks.


ThreadLocal (local thread variable) ~ ~ ~
The data is stored inside the thread, and the data is passed through the threads object execution, and each thread saves its own
Data, so you can avoid the problem of multithreading concurrency security.
Essence: is a mechanism of parameter passing.
1. Create objects
private static threadlocal<connection> TL = new threadlocal<connection> () {
Protected Connection InitialValue () {
try {
return Daoutils.getconn ();
} catch (SQLException e) {
E.printstacktrace ();
throw new RuntimeException (e);
}
}
};
2, the common method
Set (Object obj)


Get ()
InitialValue ()
public void Remove ()

Notes ~ ~ ~
Reflection annotations

!!! Dynamic Agent

Java-web Review Stage 2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.