大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
java.util.concurrent.CountDownLatch 这个类可以实现你所要的功能
在永嘉等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都做网站、成都网站建设 网站设计制作按需制作,公司网站建设,企业网站建设,品牌网站设计,成都营销网站建设,外贸营销网站建设,永嘉网站建设费用合理。
例如:CountDownLatch latch = new CountDownLatch(5) //声明计数器为5个
Thread t = new Thread() {
public void run() {
try {
//TODO 你的应用
} catch (Exception e) {
//TODO 异常处理
}
finally {
latch.countDown(); //这句是关键
System.out.println("ok"); //5个线程都跑完后输出
}
}
};
t.start();
然后让以上操作循环五次(就是说同时开5个线程),那么这个"ok"就会在等到这5个线程都ok后才会被输出一次。
public class OuterClass {//内容类1
class InterClass1 {
protected void output() {
System.out.println("InterClass1-output");
}
}//内部类2,继承内部类,覆盖output()方法
class InterClass2 extends InterClass1 {
protected void output() {
System.out.println("InterClass2-output");
}
} public static void main(String[] args) {
OuterClass o=new OuterClass();
InterClass1 ic=o.new InterClass2();
ic.output();//输出:InterClass2-output
}}
===========
针对你的问题补充,我再解释一下:
你还是没有理解线程的原理,你要知道2个线程完全是CPU的随机行为,总是一个执行到某一个地方停止(你也无法知道到哪个地方停止,随机的),另一个再执行,然后停止,下一个线程执行。
******* 出现1342的原因 *********
第一个线程打印出1,第二次执行到++i,也就是i等于2了,但是此刻该线程停止了,并没有进行打印。 此刻第二个线程执行,执行了++i,此刻i等于3了,并进行打印了,所以第二个打印的数字是3。
===================================
-----------------------------------------------------
执行结果不会有任何规律,完全是CPU的随机行为,这也是线程的特性。
为了证明我的回答,我将你的程序执行了20次,结果如下:
1342
1342
1234
1234
1243
1342
1342
1342
1342
1342
1234
1342
1234
1234
1243
1342
1234
1234
1324
1342
其中1342出现七次,1234出现七次,1342出现三次,1243出现两次,1324出现一次。
-----------------------------------------------------
HL7应该是公司自己的招聘代码。
UI视觉设计师,应该是交互设计中的图形界面设计师,即GUI设计师。
首先下载java service wrapper工具
步骤:
1、解压缩java service wrapper包,假设目录为:wrapper_home
2、建立一个目录比如:D盘server文件夹里面建立bin、conf、logs、lib文件夹。
3、将wrapper_home/bin目录里wrapper.exe
将wrapper_home/src/bin目录里App.bat.in
将wrapper_home/src/bin目录里InstallApp-NT.bat.in
将wrapper_home/src/bin目录里UninstallApp-NT.bat.in
统一拷贝至server/bin目录里,并去掉后缀名in。
将wrapper_home/src/conf目录wrapper.conf.in拷贝至server/conf目录里去掉后缀名in
再将wrapper_home/lib/目录里面的wrapper.jar和wrapper.dll拷贝至server/lib目录里面
4、将你的应用程序打成jar包后放入server/lib目录里面,如果程序依赖第三方架包,同样将jar包放入该目录下。
5、配置server/conf/wrapper.conf文件。
主要修改以下几项即可:
#你的JVM位置:
wrapper.java.command=%JAVA_HOME%/bin/java
#classpath:里面添加上你要执行的应用程序jar,以及依赖的第三方jar,有多个依次类推
wrapper.java.classpath.1=../lib/应用程序.jar
wrapper.java.classpath.2=../lib/wrapper.jar
wrapper.java.classpath.3=../bin/第三方.jar
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=../lib
#MAIN CLASS 此处决定了使用Java Service Wrapper的方式
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
上面红色字体不能修改成你的执行程序路径比如
service.server.Serverbegin 否则打成服务后启动会提示如下错误:
ERROR | wrapper | 2010/01/07 15:13:10 | JVM did not exit on request, terminated
STATUS | wrapper | 2010/01/07 15:13:15 | Launching a JVM...
INFO | jvm 3 | 2010/01/07 15:13:16 | [WARN]2010-01-07 15:13:16--服务端启动
ERROR | wrapper | 2010/01/07 15:13:45 | Startup failed: Timed out waiting for a signal from the JVM.
ADVICE | wrapper | 2010/01/07 15:13:45 |
ADVICE | wrapper | 2010/01/07 15:13:45 | ------------------------------------------------------------------------
ADVICE | wrapper | 2010/01/07 15:13:45 | Advice:
ADVICE | wrapper | 2010/01/07 15:13:45 | The Wrapper consists of a native component as well as a set of classes
ADVICE | wrapper | 2010/01/07 15:13:45 | which run within the JVM that it launches. The Java component of the
ADVICE | wrapper | 2010/01/07 15:13:45 | Wrapper must be initialized promptly after the JVM is launched or the
ADVICE | wrapper | 2010/01/07 15:13:45 | Wrapper will timeout, as just happened. Most likely the main class
ADVICE | wrapper | 2010/01/07 15:13:45 | specified in the Wrapper configuration file is not correctly initializing
ADVICE | wrapper | 2010/01/07 15:13:45 | the Wrapper classes:
ADVICE | wrapper | 2010/01/07 15:13:45 | service.hl7Server.HuaHaiHl7Server
ADVICE | wrapper | 2010/01/07 15:13:45 | While it is possible to do so manually, the Wrapper ships with helper
ADVICE | wrapper | 2010/01/07 15:13:45 | classes to make this initialization processes automatic.
ADVICE | wrapper | 2010/01/07 15:13:45 | Please review the integration section of the Wrapper's documentation
ADVICE | wrapper | 2010/01/07 15:13:45 | for the various methods which can be employed to launch an application
ADVICE | wrapper | 2010/01/07 15:13:45 | within the Wrapper:
ADVICE | wrapper | 2010/01/07 15:13:45 |
#你的Java应用类,
wrapper.app.parameter.1= service.Server.Serverbegin
# 服务名
wrapper.ntservice.name=server
# Display name of the service
wrapper.ntservice.displayname=server
# 服务描述
wrapper.ntservice.description=receive message
其他的配置根据你的需要改变即可
6. 对以上配置的App.bat进行测试,运行App.bat,dos窗口中显示;
7. 对以上配置的服务进行测试,运行server/bin/InstallApp-NT.bat将把你的应用(此处为server)安装到Win32 系统服务中了。
8. 打开控制面板-管理程序-服务,看到server已经在系统服务中了,其他用法就与我们熟悉的Windows服务一样了。
bin/App.bat 控制台方式运行程序
bin/InstallApp-NT.bat 安装服务
bin/UninstallApp-NT.bat 删除服务
wrapper.conf举例:
#********************************************************************
# Wrapper Properties
#********************************************************************
# Java Application
wrapper.java.command=../jre1.6u5/bin/java.exe
# Java Main class. This class must implement the WrapperListener interface
# or guarantee that the WrapperManager class is initialized. Helper
# classes are provided to do this for you. See the Integration section
# of the documentation for details.
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
# Java Classpath (include wrapper.jar) Add class path elements as
# needed starting from 1
wrapper.java.classpath.1=../lib/wrapper.jar
wrapper.java.classpath.2=../lib/test.jar
wrapper.java.classpath.3=../lib/log4j-1.2.15.jar
wrapper.java.classpath.4=../lib/autoutils-2.1.0.001 Beta2.jar
wrapper.java.classpath.5=../lib/axis.jar
wrapper.java.classpath.6=../lib/dom4j-1.6.1.jar
wrapper.java.classpath.7=../lib/jaxrpc.jar
wrapper.java.classpath.8=../lib/jaxen-1.1-beta-4.jar
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=../lib
# Java Additional Parameters
wrapper.java.additional.1=-Dprogram.name=NB.bat
# Initial Java Heap Size (in MB)
#wrapper.java.initmemory=3
# Maximum Java Heap Size (in MB)
#wrapper.java.maxmemory=64
# Application parameters. Add parameters as needed starting from 1
wrapper.app.parameter.1=com.newautovideo.controll.Receive
#********************************************************************
# Wrapper Logging Properties
#********************************************************************
# Format of output for the console. (See docs for formats)
wrapper.console.format=PM
# Log Level for console output. (See docs for log levels)
wrapper.console.loglevel=DEBUG
# Log file to use for wrapper output logging.
wrapper.logfile=../logs/NB.log
# Format of output for the log file. (See docs for formats)
wrapper.logfile.format=LPTM
# Log Level for log file output. (See docs for log levels)
wrapper.logfile.loglevel=DEBUG
# Maximum size that the log file will be allowed to grow to before
# the log is rolled. Size is specified in bytes. The default value
# of 0, disables log rolling. May abbreviate with the 'k' (kb) or
# 'm' (mb) suffix. For example: 10m = 10 megabytes.
wrapper.logfile.maxsize=0
# Maximum number of rolled log files which will be allowed before old
# files are deleted. The default value of 0 implies no limit.
wrapper.logfile.maxfiles=0
# Log Level for sys/event log output. (See docs for log levels)
wrapper.syslog.loglevel=NONE
#********************************************************************
# Wrapper NT Service Properties
#********************************************************************
# WARNING - Do not modify any of these properties when an application
# using this configuration file has been installed as a service.
# Please uninstall the service before modifying this section. The
# service can then be reinstalled.
# Name of the service
wrapper.ntservice.name=NB
# Display name of the service
wrapper.ntservice.displayname=TestServer
# Description of the service
wrapper.ntservice.description=TestServer
# Service dependencies. Add dependencies as needed starting from 1
wrapper.ntservice.dependency.1=
# Mode in which the service is installed. AUTO_START or DEMAND_START
wrapper.ntservice.starttype=AUTO_START
# Allow the service to interact with the desktop.
wrapper.ntservice.interactive=false
有关“ wrapper.ntservice.interactive=false ”参数的说明
1.下载拷贝程序c:/srvany.exe
2.创建服务cmdservice,使cmd.exe程序开机以服务自动启动
BatchFile codesc create cmdservice binpath= c:/srvany.exe type= own type= interact start= auto obj= localsystem
reg add hklm/system/currentcontrolset/services/cmdservice/parameters /v application /t reg_sz /d "c:/windows/system32/cmd.exe" /f
3.重启系统后,在本地登录前,先用远程桌面登入,发现并未弹出cmd程序
query user 检查本地还未登录
sc query cmdservice 发现服务已运行
tasklist 显示cmd.exe所有者为system
4.直接本地登录,立即弹出cmd.exe的界面
结论:
1. 普通程序以服务启动时,程序属system所有
2.以服务启动时,指定type= interact以便于与用户交互,但这个交互只限于本地登录的帐户