4 threads were designed, of which two threads increased by 1 for J each time, while the other two threads reduced by 1 for J at a time. Write a program
The following program implements threads using an internal class, and does not consider order issues when adding or subtracting J.
Public class ThreadTest1{ Private intJ Public Static voidMain (String args[]) {ThreadTest1 tt=NewThreadTest1 (); Inc Inc=tt.NewINC (); Dec Dec=tt.NewDec (); for(intI=0;i<2; i++) {Thread t=NewThread (INC); T.start (); t=NewThread (DEC); T.start (); }}PrivateSynchronizedvoidInc () {j + +; System.out.println (Thread.CurrentThread (). GetName () +"-inc:"+J); }PrivateSynchronizedvoidDec () {j--; System.out.println (Thread.CurrentThread (). GetName () +"-dec:"+J); } class Inc implements Runnable{ Public voidRun () { for(intI=0;i< -; i++) {Inc (); }}} class Dec implements Runnable{ Public voidRun () { for(intI=0;i< -; i++) {Dec (); } } }}
Does Java have a goto?
Reserved words in Java are not currently used in Java.
30. Start a thread with run () or start ()
Starting a thread is calling the start () method so that the virtual processor represented by the thread is in a running state, which means it can be dispatched and executed by the JVM. This does not mean that the thread will run immediately. The run () method can produce a flag that must be exited to stop a thread.
31, EJB includes (Sessionbean,entitybean) say their life cycle, and how to manage the transaction
The lifecycle of the sessionbean:stateless Session Bean is determined by the container, and when the client makes a request to establish an instance of the bean, the EJB container does not have to create a new instance of the bean for the client to invoke. Instead, find an existing instance to provide to the client. When a client invokes a stateful session bean for the first time, the container must immediately create a new bean instance in the server and associate it with the client, which in the future calls the stateful session bean method, the container assigns the call to the bean instance associated with the client.
Entitybean:entity beans can survive for a relatively long time, and the state is persistent. As long as the data in the database exists, Entity beans has survived. Not according to the application or service process. Even if the EJB container crashes, the Entity beans is alive. The Entity beans life cycle can be managed by the container or beans itself.
EJB is managed by the following technologies: Object Management Organization (OMG), Transaction Service (JTS), Java Transaction API (JTA), Development Group (x/), Microsystems Services (OTS) Open) of the XA interface.
32, the application server has those
BEA WebLogic SERVER,IBM WebSphere application server,oracle9i application Server,jboss,tomcat
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
5 questions per day (vi) Java basics