1. Set in the Web container (for example, Tomcat here)Set in Tomcat-5.0.28\conf\web.xml, the following is the default configuration in Tomcat 5.0:[HTML] View plain copy
-
session-config>
session-timeout>30session-timeout>
session-config>
Tomcat default session timeout is 30 minutes, can be modified as needed, negative or 0 is not limit session failure time.2. Set up in the project's Web. xml[HTML] View plain copy
3. Using
the face of complex serialization or reflection attacks. * Single-element enumeration types have become the best way to implement Singleton. * @author Liu Xiangfeng * * * * Public enumEnumsingleton {INSTANCE; Public void leavethebuilding(){}}/** * Serialization of Singleton mode * @author Liu Xiangfeng * */ Public class Serializesingleton implements Serializable { //Declare all instance domains to be instantaneous transient Private Static FinalSerializesingleton INSTANCE =NewSerializesin
domain: Recursively calling the Equals methodFloat field: Float.compare methodDouble field: Double.compare methodE, after completing the Equeal method, ask yourself three questions: Is it symmetrical, transitive, and consistent?3. Some cautions1, after covering the Equals method, be sure to overwrite the Hashcode method2. Do not attempt to make the Equals method too intelligent3. Do not replace object objects in the equals declaration with other types4. Note Using @override annotations to ensur
using the builderPackage theone;public class Twoobject {private int A;private int B;private int C;public static class Bulider {private int A;private int B;private int C;Public Bulider A (int a) {THIS.A = A;return this;}Public Bulider B (int b) {this.b = b;return this;}Public Bulider C (int c) {THIS.C = C;return this;}Public Twoobject Bulid () {return new Twoobject (this);}}Public Twoobject (Bulider b) {THIS.A=B.A;this.b=b.b;THIS.C=B.C;}public static void Main (string[] args) {Twoobject to=new T
A few days ago Amazon accidentally recommended this book, online search for the next introduction, found to be very interested in the form.Instead of flipping through the basics, the author uses the best practices to present them.And did not spend valuable space on the programming of graphical interfaces. Then decisive order.-----After reading the introduction of the first chapter, as expected, some places are not fluent in translation, but do not affect understanding. The book is divided into 1
Avoid over-synchronizationIn order to avoid active failure and security failures, a synchronized method or code is fast, never give up control of the client.Because it's alien, it's not controlled.Move the foreign method call out of the synchronized code fast.Create a SnapshotUse concurrent collections, copyonwritearaylist. A Variant that belongs to ArrayList, where all writes are implemented by copying the entire underlying array. Because the internal data is used for no change, the iterations
parameterless builder method to generate the immutable object. This method is more flexible and easy to read, and can increase the constraint condition for the parameter. It also has its own shortcomings, such as in some very performance-oriented circumstances, its overhead may be problematic. This pattern is more verbose than an overlapping constructor, so it is used only when a number of parameters are available, especially when most parameters are optional.Third #, hardening the Singleton pr
projects agreed by the company code. If improving code quality is the primary goal, then PMD is a good choice. But if you want more features and really use tools to modify the code, you should try jalopy.
jalopy, Jalopy is an easy to configure source code format program that detects and fixes a large number of custom bugs in Java code. Jalopy is more like a code-builder than an inspector. Jalopy's plug-ins now support most Ides, and most are seamles
I. BACKGROUND
For some tool classes such as Java.lang.Math, Java.util.Arrays, and so on, they contain only static methods and static field fields, and there is no point in instantiating such a class. But in practice, such a class can be instantiated just like any other class without any special handling.
Ii. Methods of Treatment
The constructor is set to private so that the outer class cannot instantiate the class and throw an exception directly in the private constructor to avoid being insta
Tag: Is the CER object type call error arraylist conversion extend compilerToday will be effective Java (second edition) in the generic part of the reading, deep understanding of their own generic mastery of how unskilled, or need more practice.Say less nonsense, on the point of focus:1. Do not use prototypesLike what:New ArrayList ();When you use the list reference to point to other lists with generics, th
keep the failure atomicA failed method call should keep the object in the state it was before it was called, and there are several ways to do so
Using Immutable objects
Check parameter validity before changing state, throw exception early
Put the potentially failed action before the change state, so that the failure can end prematurely without leaving the object in an inconsistent state
Write recovery code (infrequently used), typically for data that has persisted
To ma
1, consider using the static factory method instead of the constructor.Here are some advantages:
The static method factory method has a variable name. For example, a true object defined in a Boolean class with a name that is very intuitive.
Boolean.truepublic static Final Boolean true = new Boolean (true);
You do not have to create new objects every time you call. If creating objects is expensive, using static classes can improve performance.
Any subcla
Chapter II Creating and Destroying objectsThe first one uses the static factory method instead of the constructor, because:
Static factory methods can have different names, that is, the constructor can only be distinguished by different parameters, and static factories can express different purposes in their names.
The static factory method creates a new object without each invocation (in fact because it is static, so it can only be used as static, so it is created early and does not need
.item27; Public classgenericsingletonfactory{//Create object objects first, temporarily override T objects Private StaticUnaryfunctionNewUnaryfunction() { Publicobject Apply (object arg) {returnArg; } }; //according to T, the identity_function is converted to the corresponding type, because Identity_function returns the object type parameter unmodified, so the following type conversion is safe@SuppressWarnings ("Unchecked") Public Staticidentityfunction () {return(una
= = 23) { //Thread pool, which creates a thread pool of a single threads, creates a new thread instead of executing the task if the current thread breaks abruptly when the task is executedExecutorservice executor =Executors.newsinglethreadexecutor (); Finalsetobserver This; Try{executor.submit (NewRunnable () {@Override Public voidrun () {//There's going to be a deadlock.Set.removeobserver (Observer); }}). get (); } Catch(i
the general conventions of Object.hashcode, which prevents the class from working properly with all hash-based collections, such as Hashmap,hashset and Hashtable.always overwrite ToStringThis item is mostly intended to provide the necessary critical information when printing data, because the default ToString method only returns the unsigned hexadecimal representation of the class name [email protected]+ hash code.cover clone with careThe purpose of the Cloneable interface is expressed as an ob
; } Public Static voidMain (string[] args) {Builderdemo demo=NewBuilder (calories). Carbohydrate (43). build (); }}Such code is easy to write and read. Furthermore, constraints can be imposed on their parameters, and the build method can examine these constraints, copy the parameters from the builder to the object, and test them in the object domain.Insufficient builder mode: 1. You need to create the builder before creating the object, which is not applicable in a very performance-oriented
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.