Wednesday, November 6, 2013volatile keyword: 1. Almost the same as synchronized, but volatile is better than 2 when it reads and writes less. When you define member variables, you can guarantee that each read member variable is read from shared memory and that the values are guaranteed to be equal concurrentlinkedqueue: 1. Lock-free, concurrent thread-safe queue2. To determine whether it is empty, size () traverses the entire collection and takes a long time to use IsEmpty () You cannot use Putall when map is Emptymap, otherwise the java.lang.UnsupportedOperationExceptionexceptions,Because Collection.emptymap () this mapping does not supportputOperation, and specifies that the mapping is non-emptythe emptymap here is not NULL, nor is it a new collection of size = 0, NULL would not have supported Putall operations, Size=0 would putall Friday, December 20, 2013The List and array are converted to each other:List-to- array:string[] Array = (string[]) List.toarray (new String[list.size ()]); Arrays--List:list<string> list=arrays.aslist (array);http://www.iteye.com/topic/418542
- New Hashset<string> () {{
- Add ("xz13s");
- Add ("ab21/x");
- Add ("Yylex");
- Add ("ar2d");
- }};
The actual definition is an internal anonymous class (Anonymous Inner Class), and the second layer of parentheses is actually an instance initialization block (instance initializer block), which is executed when the inner anonymous class is constructed. This method only applies to
Wednesday, February 12, 2014
final modified variables are not modifiable, but container types are specialfor instance constants that are static and final modified, the instance itself can no longer be changed, but for instance variables of some container types (for example, ArrayList, HashMap), the container variable itself cannot be changed, but the object stored in the container can be modified. Your needs may need to be wrapped in a class to implement. Jsonarray is an array of jsonobject:
Friday, February 21, 2014
Time Processing long time = system.currenttimemillis (); Current time in // long type Date Date = new date (Time); // converted to date type simpledateformat sdf = new simpledateformat ("Yyyy-mm-dd hh:mm:ss "); // set format calendar cal = calendar.getinstance (); // instantiation, also get current time Cal.settime (date); // Incoming Time int day = cal.get (calendar.day_of_month); // int type of days int month = cal.get (Calendar.month) + 1; // months, do not know why must be +1&nbsP;int year = cal.get (calendar.year); Number of // years Http://code.taobao.org/p/gecko/wiki/design-core/teaches you to see the Gecko Framework code (in fact, Netty simplified version) http://wenku.baidu.com/view/ 01324f0f79563c1ec5da718a.htmlhttp://weixiaolu.iteye.com/blog/1479656http://xmuzyq.iteye.com/blog/783218
Saturday, April 12, 2014http://www.cnblogs.com/mengdd/archive/2013/02/16/2913806.html Examples of synchronized
If an object has multiple synchronized methods and a thread has entered a synchronized method at some point, the other thread is unable to access any of the synchronized methods of the object until the method has finished executing.
Conclusion:
When the Synchronized keyword modifies a method, the method is called a synchronous method.
Each object in Java has a lock, or monitor, that locks the object when a thread accesses the synchronized method of an object. No other thread can access the object's Synchronized method (this refers to all synchronous methods, not just the same method) until the previous thread executes the method (or throws an exception) before releasing the object's lock. Other threads will be able to access the object's synchronized method again.
Note that this is a lock on the object , and if it is a different object, there is no restriction between the objects.
If a synchronized method is static, then when the thread accesses the method, it locks not the object that the Synchronized method resides in, but the class object that corresponds to the synchronized method. In Java, no matter how many objects a class has, these objects correspond to a unique class object, so when a thread accesses two static,synchronized methods of two objects of the same class individually, their order of execution is also sequential, that is, a thread first executes the method, Another thread does not start until after execution is complete.
The synchronized method is a coarse-grained concurrency control where only one thread can execute the synchronized method at a time;
Java meta annotations
@Target(elementtype.[ Type]), which means that the method is used
[Type]={method, FIELD, type (class, interface, enum Declaration), CONSTRUCTOR, local_variable, PARAMETER (parameter)}
@Retention(Retentionpolicy. [Policy]) Defining retention policies for annotations
[Policy]={source, Class, RUNTIME (Reflection mechanism readable)} source//annotations only exist in the source code, in the CLASS bytecode file does not contain class //default retention policy, annotations exist in the class bytecode file, but are not available at runtime
Runtime //annotations exist in the class bytecode file and can be retrieved at run time through reflection
@Documented indicates that this annotation is included in the Javadoc
@inherited means that subclasses are allowed to inherit annotations from the parent class
Common Annotation Analysis for spring and JUnit.
@Test The annotation is under Spring, the annotated method can be run directly to test the program
How to design and use annotations rationally
Annotations are used to mark fields and methods to intercept the metadata of annotations and their tagged fields and methods by reflection, and to process metadata as required.
It gives extra meaning to fields and methods, and provides an elegant way to work with fields and methods uniformly.
Note more meaning is to provide a design pattern, in essence it does not enhance the ability of Java, the use of annotations to implement the function can be implemented in a non-annotated way, but the code may not be very good-looking
Java Problem Collection