- 浏览: 415465 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (203)
- 管理 (9)
- 情感 (3)
- 技术 (43)
- jfreeChart (5)
- unix (6)
- webService (3)
- 权限管理 (2)
- spring (3)
- log4j (2)
- java性能测试 (2)
- dwr (1)
- 数据迁移 (4)
- derby数据库基础 (1)
- jsp前台 (4)
- 线程 (6)
- 企业信息化 (2)
- 技术基础 (2)
- 经典算法 (1)
- 数据库性能 (7)
- 个人规划 (8)
- xml (2)
- ftp传输 (1)
- socket (3)
- java技术之正则表达式 (2)
- java技术之io操作 (1)
- java技术之常用命令程序使用方法 (1)
- interview (8)
- eclipse插件安装 (3)
- UML (1)
- oracle (29)
- java (3)
- 航空信息 (3)
- 读书 (1)
- Intellij idea (0)
- linux (24)
- 服务器架构 (4)
- weblogic (3)
最新评论
-
tuspark:
关于eclipse插件安装方法,这里文章图文并茂,讲解的最详细 ...
eclipse插件安装方法总结 -
swanky_yao:
非常不错 受益匪浅
j2ee异常处理机制 -
菜鸟不再菜:
如果能拿一个项目的例子来说明一下就好了~
j2ee异常处理机制 -
Q.Lee:
不出现异常了,但是访问http://localhost:808 ...
dwr使用异常 -
Q.Lee:
崩溃。。。。。
dwr使用异常
命令工厂:
public class CommandFactory { public static CommandLine createCommand(String command ,String[] parameter){ if(null == command || "".equals(command)){ System.out.println("the command must not null!") ; return null ; } return createJavaCommand(command, parameter) ; } private static CommandLine createJavaCommand(String command ,String[] parameter){ //final String SPLIT = " " ; if(null == parameter || parameter.length < 1){ return new CommandLine(command) ; } else { return new CommandLine(command,parameter); } } }
命令处理器:
public class CommandHandler { public static void excute(CommandLine command) throws IOException, InterruptedException { if (null == command || "".equals(command)) { System.out.println("the parameter[command] must not null!"); return; } try { System.out.println("execute command start:" + command) ; Runtime runtime = Runtime.getRuntime(); Process pro = runtime.exec(command.toString()); SimpleThreadPool queue = SimpleThreadPool.getWorkQueue(4) ; CommandStream commandStream = new CommandStream(); commandStream.setCharset("gbk") ; commandStream.setCommandLine(command) ; commandStream.setIs(pro.getInputStream()) ; commandStream.setType("IN") ; queue.postCommandStream(commandStream) ; commandStream = new CommandStream(); commandStream.setCharset("gbk") ; commandStream.setCommandLine(command) ; commandStream.setIs(pro.getErrorStream()) ; commandStream.setType("ERROR") ; queue.postCommandStream(commandStream) ; int exitVal = pro.waitFor() ; System.out.println("execute command end:" + command + " exit value:" +exitVal) ; } catch (IOException e) { e.printStackTrace() ; throw e ; } catch (InterruptedException e) { e.printStackTrace() ; throw e ; } } }
命令行:
public class CommandLine { private String command ; private String[] parameters ; /** * @param command * @param parameters */ public CommandLine(String command, String[] parameters) { if(command == null || "".equals(command)) { throw new IllegalArgumentException("the parameter[command] must not null!") ; } if(parameters == null ) { throw new IllegalArgumentException("the parameter[parameters] must not null!") ; } this.command = command; this.parameters = parameters; } /** * @param command2 */ public CommandLine(String command) { this.command = command ; } public String toString() { StringBuilder sb = new StringBuilder() ; final String split = " " ; sb.append(command + split) ; for(String parameter : parameters) { sb.append(parameter+split) ; } return sb.toString() ; } }
命令流:
public class CommandStream { /** * @return the commandLine */ public CommandLine getCommandLine() { return commandLine; } /** * @param commandLine the commandLine to set */ public void setCommandLine(CommandLine commandLine) { this.commandLine = commandLine; } private CommandLine commandLine ; private String type ; /** * @return the type */ public String getType() { return type; } /** * @param type the type to set */ public void setType(String type) { this.type = type; } private InputStream is; private String charset = "gbk" ; /** * @return the is */ public InputStream getIs() { return is; } /** * @param is the is to set */ public void setIs(InputStream is) { this.is = is; } /** * @return the charset */ public String getCharset() { return charset; } /** * @param charset the charset to set */ public void setCharset(String charset) { this.charset = charset; } }
命令处理器:
public class CommandStreamHandler extends Thread{ private SimpleThreadPool queue ; private volatile boolean run = true ; public void run(){ while (run) { CommandStream commandStream = queue.selectCommandStream(); if (null != commandStream) { handleEvent(commandStream); } } } /** * @param commandStream * @Description: */ private void handleEvent(CommandStream commandStream) { InputStreamReader isr = null ;; BufferedReader br = null; try { isr = new InputStreamReader(commandStream.getIs(),commandStream.getCharset()); br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) { System.out.println(commandStream.getType()+">>>>>>>>>>>>>>>>>" + line) ; } } catch (IOException ioe) { ioe.printStackTrace(); }finally { if(br != null) { try { br.close() ; } catch (IOException e) { e.printStackTrace(); } } } } /** * @param workQueue * @Description: */ public void setQueue(SimpleThreadPool workQueue) { this.queue = workQueue ; } public void toStop(){ this.run = false ; } }
线程池:
public class SimpleThreadPool { /** * 默认的最大任务数。 */ private static final int DEFAULT_MAX_TASK_NUM = 5; /** * 最大任务数。仅对会话任务限制。 */ private int maxTaskNum = DEFAULT_MAX_TASK_NUM; public LinkedList<CommandStream> commandQueue = new LinkedList<CommandStream>(); /** * 队列 */ public CommandStreamHandler[] handlerQueue ; private static SimpleThreadPool instance ; public static SimpleThreadPool getWorkQueue(int number){ if(instance == null) { instance = new SimpleThreadPool(number); } return instance ; } private SimpleThreadPool(int number){ start(number) ; } private void start(int number) { handlerQueue = new CommandStreamHandler[number]; for (int i = 0; i < number; i++) { handlerQueue[i] = new CommandStreamHandler(); handlerQueue[i].setQueue(this); handlerQueue[i].setContextClassLoader(Thread.currentThread() .getContextClassLoader()); // handlerQueue[i].setDaemon(true) ; handlerQueue[i].start(); } } /** * 任务入队 * * @param commandStream * @return false入队失败 */ public boolean postCommandStream(CommandStream commandStream) { synchronized (commandQueue) { // 当排队任务超过最大任务数时,禁止会话任务加入 if (commandQueue.size() > maxTaskNum) { return false; } // 加入任务 commandQueue.add(commandStream); // 唤醒一个等待的处理线程 commandQueue.notify(); } return true; } /** * 取得一个任务。当队列为空时wait。 * * @return */ public CommandStream selectCommandStream() { CommandStream handler = null; synchronized (commandQueue) { while (commandQueue.size() == 0) { try { commandQueue.wait(); } catch (InterruptedException e) { return null; } } if (commandQueue.size() > 0) { handler = commandQueue.remove(); } else { handler = null; } } return handler; } public int getMaxTaskNum() { return maxTaskNum; } public void stop() { for(CommandStreamHandler handler : handlerQueue) { handler.toStop() ; } } }
发表评论
文章已被作者锁定,不允许评论。
-
WIN10 下 IE11 F12开发者工具无法debug断点调试js
2016-03-03 12:26 10114前段时间买了新电脑,安装的是win10系统,开发程序时需要 ... -
更改ejs模板后缀.ejs为.html
2015-03-25 16:12 719app.engine('.html', require('e ... -
npm设置http代理
2015-03-25 15:32 1314node.js 的npm命令是node.js的包管理工具,安 ... -
ERROR Deployer not found: git
2015-03-23 01:39 0出现该问题基本原因是由于没有安装hexo-deployer- ... -
webstorm install
2015-03-22 23:36 955在安装hexo前,需要先安装webstorm,并通过web ... -
centos6 git github
2015-03-22 23:30 850git的出现让传统的svn陷入尴尬的境地,分布式的版本控制 ... -
centos6 nodejs install
2015-03-22 22:02 564准备命令: yum -y install gcc ma ... -
fcitx安装
2015-03-21 00:13 822CentOS安装fcitx方法 因为选择的是最小安装 ... -
_jspxFactory nullpointException
2012-11-01 11:12 1028exception org.apache.jas ... -
preparedstatement execute()操作成功!但是返回false
2012-10-22 10:58 2803boolean b = ps.execute();//这 ... -
如何用 SQL Tuning Advisor (STA) 优化SQL语句
2011-08-26 10:46 1067在Oracle10g之前,优化SQL是个比较费力的技术活, ... -
谈谈对于技术面试的心得体验
2011-02-10 14:10 970只要是招一个技术人 ... -
eclipse3.4从svn导出后html中文乱码
2010-09-25 11:54 1817问题描述:从svn中check out一个工程,然后给工程设置 ... -
使用break+label配合跳出多重循环
2010-03-24 10:34 1747签语句是在某个语句前面加上个标识符以及一个冒号 . 标签在 b ... -
工程中使用java代码加载第三方jar文件
2010-03-24 10:33 4250package com.send.start; impo ... -
jar命令使用遇到问题
2010-03-24 10:32 1296jar cvfm stup.jar ../list.txt - ... -
数据库中取出的值判断
2010-03-05 16:56 1008//数据库中取出的值判断时,经常出现使用null和“”都判断不 ... -
批处理删除svn文件与clas文件
2010-03-04 11:01 1589package com.delete.dir; impo ... -
压缩与解压缩文档
2009-12-29 21:11 1289package com.sjs; import java ... -
java程序中调用数据库中的存储过程
2009-11-27 12:32 994public static void aa(String jo ...
相关推荐
Java程序是如何执行CMD命令的,就是需要RunTime、Process类而已。 具体代码在文档中
主要介绍了java运行windows的cmd命令简单代码,有需要的朋友可以参考一下
java代码-//运行cmd命令并返回结果
打开windows命令行(运行=>cmd=>回车),在命令行中 进入 EncryptJar目录 2.执行 java -jar encrypt.jar 3.输入h,然后回车,可以看到帮助菜单 4.输入3,然后按回车键,进入加入jar文件功能 5.输入要加密的jar文件的...
参考了java版的expect4j,expectj的原理,进行了极大的简化,可完成基本的功能: 1,运行java代码,执行交互式命令 2,sudo提权,自动输入密码(echo "password" | sudo -S mkdir /opt/test)
本例子用cmd命令运行该项目,方便快捷,代码多行注释,方便阅读理解,包含运行的cmd命令。
主要给大家介绍了关于将java程序打成jar包在cmd命令行下执行的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。
2.在当前目录下运行cmd , 在命令框中执行 指令.txt 文档中的命令 3.执行成功后 就可以在你配置的生成文件存放路径中 找到你想要的java代码类和xml 文件 注意: 1.库表一定要配置正确 2.数据库字段命名建议规范(全大写...
启动dos窗口 win+R 输入cmd 输入jshell 直接可以敲java代码 3.1:JAVA开发工具包 JRE、JDK、JVM JRE是java运行环境,运行java所必需的文件 JDK是开发工具包,增加编译器和调试器等用于程序开发的文件 JVM是java的...
windows开始 -> 运行 -> cmd -> 进入msdos命令窗体 java java执行命令 使用Java虚拟机JVM运行编译后的字节码文件 javac java编译命令 将java原代码文件.java编译成字节码文件.class java -version 显示当前...
Java商城网站系统设计与实现基于java+springboot+vue开发的电子商城网站-毕业设计-课程...cmd命令进入web目录下,安装依赖,执行: npm install 运行项目 npm run dev 在浏览器输入: http://localhost:3000 即可预览
以我的为例,操作步骤如下: 我将class文件FileSa.class和jad放在E盘根目录下; 打开“命令提示符”快捷键操作:WIN+R; 再依次如下几步: cmd 回车;... 注3:要运行,在命令提示符中输入java FileSa即可
管理员对图书信息的增删改查、查看读者、查看...如果不想用IDE打开项目而是想直接运行的朋友们,在目录下打开cmd键入mvn package命令,然后在target/目录下会生成对应的jar包,在cmd用“java -jar jar包名”运行即可
使用步骤: ...2.在当前目录下运行cmd , 在命令框中执行 指令.txt 文档中的命令 3.执行成功后 就可以在你配置的生成文件存放路径中 找到你想要的java代码类和xml 文件 注意: 1.库表一定要配置正确
二、从解压缩的文件夹中取出classes.dex文件并放到dex2jar.bat所在目录,运行cmd命令, 进入dex2jar.bat所在的目录,输入dex2jar.bat classes.dex即可生成classes.dex.dex2jar.jar文件 三、用jd-gui工具打开classes...
jre:当一个电脑上面安装jre之后 只能运行java代码 2:设置环境变量 (环境变量可以不设置 为了简化开发流程 提高开发效率) 给谁使用 作用 PATH: 操作系统 让操作系统更加快捷的找到一个文件/命令 PATH=C:\...
android反编译,android的apk反编译工具,适合大家一起学,可以把android生成的apk转为java代码,希望对大家有用。 一、更改apk文件的后缀名,如:LianyunHelper3.0.11.apk改成LianyunHelper3.0.11.zip 二、用zip解...
android反编译,android的apk反编译工具,适合大家一起学,可以把android生成的apk转为java代码,希望对大家有用。 一、更改apk文件的后缀名,如:aa.apk改成aa.zip 二、用zip解压缩aa.zip文件 三、从解压缩的文件夹中...
2、在cmd命令窗口输入services.msc,找到MYSQL服务选项,如果没有启动则需要手动启动它。 3、进入navicatformysql界面,进行数据库连接测试,测试成功后创建数据库(在powerdesigner中生成的可运行sql脚本)。 4、...
任何时候只要您想编写简单的程序来测试代码或进行其他操作,请使用我制作的这些批处理文件。 它们比打开IDE并输入所有内容进行测试要快得多。 然后,批处理文件“ RunJavaCode”创建一个.class文件(字节码),然后...