Atomicinteger Introduction
This class is really practical, and more importantly, it's really very simple:
Attach your own code, you can try it yourself:
Atomicinteger, a class that provides an integer for atomic operations. In the Java language, ++i and i++ operations are not thread-safe and will inevitably use the Synchronized keyword when used. and Atomicinteger through a thread-safe addition and subtraction operation interface.
Code:
Package test;
Import Java.util.concurrent.atomic.AtomicInteger;
/**
* Look at the interface provided by Atomicinteger.
Get the current value
Public final int Get ()
Take the current value and set the new value
Public final int Getandset (int newvalue)
Gets the current value and increases itself
Public final int getandincrement ()
Get the current value and subtract
Public final int getanddecrement ()
Gets the current value and adds the expected value
Public final int getandadd (int delta)
* @author Yangbaobao
*
*/
public class Atomicintegerdemo {
public static void Main (string[] args) {
Atomicinteger ai=new atomicinteger (0);
int I1=ai.get ();
V (i1);
int I2=ai.getandset (5);
V (i2);
int I3=ai.get ();
V (i3);
int i4=ai.getandincrement ();
V (I4);
V (Ai.get ());
public void setdate (String date) {
This.date = date;
}
Public String GetMode () {
return mode;
}
public void SetMode (String mode) {
This.mode = mode;
}
Public String Getunit () {
return to Unit;
}
public void Setunit (String unit) {
This.unit = unit;
}
Public String GetCurrent () {
return to current;
}
public void Setcurrent (String current) {
This.current = current;
}
Public String getinteractive () {
return interactive;
}
public void Setinteractive (String interactive) {
this.interactive = interactive;
}
@Override
Public String toString () {
Return "Item [current=] + current +", date= "+ Date +", interactive= "
+ Interactive + ", mode=" + mode + ", unit=" + unit + "];
}
}
Class Staxparser {
Static final String date = "Date";
Static final String item = "Item";
Static final String mode = "mode";
Static final String unit = ' unit ';
Static final String current = ' current ';
Static final String INTERACTIVE = "INTERACTIVE";
@SuppressWarnings ({"Unchecked", "null"})
Public list<item> readconfig (String configfile) {
list<item> items = new arraylist<item> ();
try {
Create a new Xmlinputfactory
Xmlinputfactory inputfactory = Xmlinputfactory.newinstance ();
Setup a new Eventreader
InputStream in = new FileInputStream (configfile);
Xmleventreader Eventreader = Inputfactory.createxmleventreader (in);
Read the XML document
Item item = NULL;
while (Eventreader.hasnext ()) {
Xmlevent event = eventreader.nextevent ();
if (Event.isstartelement ()) {
Startelement startelement = Event.asstartelement ();
If we have an item element, we create a new item
if (Startelement.getname () getlocalpart () = = (ITEM)) {
item = new item ();
We read the attributes from this tag and add the date
attribute to our Object
iterator<attribute> attributes = Startelement
. GetAttributes ();
while (Attributes.hasnext ()) {
attribute = Attributes.next ();
if (Attribute.getname (). toString (). Equals (DATE)) {
Item.setdate (Attribute.getvalue ());
}
}
}
if (Event.asstartelement (). GetName (). Getlocalpart ()
. Equals (INTERACTIVE)) {
event = Eventreader.nextevent ();
Item.setinteractive (Event.ascharacters (). GetData ());
Continue
}
}
If we reach the ' end of ' an item element, we add it to the list
if (Event.isendelement ()) {
EndElement endelement = Event.asendelement ();
if (Endelement.getname () getlocalpart () = = (ITEM)) {
Items.Add (item);
}
}
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.