5 questions per day (vi) Java basics

Source: Internet
Author: User
Tags websphere application server

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

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.