将jboss 7安装成系统服务

本文自:https://community.jboss.org/wiki/RunningJBossAS7AsAWindowsService

首先从地址 http://www.jboss.org/jbossweb/downloads/jboss-native-2-0-10 下载最新的jboss native文件,将其copy到jboss的bin目录下,原bin目录是不会有native包里的东西的。然后依次进行以下操作即可

  1. 修改service.bat文件,将里面的SVCNAME, SVCDISP and SVCDESC分别修改为自己想要安装成服务的相关信息,即服务名,服务标识以及服务描述信息。
  2. 修改里面的JAVA_OPTS信息配置信息,以配置相应的java内存配置信息,在原service.bat文件中,有默认的-Xrs选项,不过这个选项先不能删掉,以避免某些远程桌面信息会导致jboss停掉的问题。此外,还需要配置比如JAVA_HOME等信息。
  3. 将service.bat中的所有run.bat修改为standalone.bat,在最新的jboss版本中,已不再使用call.bat了。
  4. 将service.bat中关于停止服务的 call shutdown 部分修改为 call jboss-cli.bat –connect command=:shutdown >> shutdown.log 2>&1。因为已经没有shutdown.bat这个文件,如果不修改的话,此调用将直接重启机器。此外,如果配置多个jboss,只需要在后面追加 –controller=host:mport 即可。
  5. 在cmd下运行 service.bat install安装服务,然后在服务中将其启动方式修改为auto即可。

继续阅读“将jboss 7安装成系统服务”

在windows下未启动oracle服务时访问idle database时出现 protocal adapter error的问题解决(转)

 本文转自:http://www.dbforums.com/oracle/1635283-how-connect-idle-instance-ora10gr1-windows2k.html,原文作者:dayneo.

 现在有一个oracle数据库还未启动,但我要手动地启动它。因此,按理说可以通过连接到一个idle的数据库,但是却发生了以下的错误(这些错误在linux下是不会发生的)

1) sqlplus sys/password@sid as sysdba
which gives
ORA-12514: TNS: listener does not currently know of service requested in connect descriptor
2) set ORACLE_SID=SID
sqlplus sys/password as sysdba
which gives
ORA-12560: TNSrotocol adapter error
3) set ORACLE_SID=SID
sqlplus / as sysdba
which gives 
ORA-12560: TNSrotocol adapter error
That one works on my Linux server by the way....
4) sqlplus "/ as sysdba"
which gives 
ORA-12560: TNSrotocol adapter error

非常让人奇怪的是监听器根本不知道还没有启动的oracle服务,那么如何让监听器知道这个服务呢,或者通过什么样的方式注册这个sid信息?

继续阅读“在windows下未启动oracle服务时访问idle database时出现 protocal adapter error的问题解决(转)”

使用js(kibo)监听浏览器键盘事件

在进行BS系统开发之时,总有客户提出某些按钮应该支持快捷键,甚至整个系统都采用快捷键来进行操作。如果没有一个有效的键盘事件处理的js框架,在每个界面处理不同的键盘事件,是一件非常可怕的事情。幸运的是,老外开发了一个有效的js框架,来监听浏览器中的键盘事件,并提供丰富的事件处理来让开发人员进行界面处理。那就是kibo,一个键盘处理js。
本文为kibo中文教程,直接从kibo官方教程翻译而来,不足之处望谅。

可以从以下网站下载最新的版本:https://github.com/marquete/kibo。整个文件才8k,足够的小,都不需要使用压缩了,而且与jquery也不冲突。它是一个简单地处理键盘事件的js library,没有其它依赖。

语法和使用
kibo主要提供了两个键盘事件的调用函数,down和up,分别表示按键的按下和弹起。这两个函数接收两个参数,一个参数为需要监听的键盘按键集合,包括一个或多个按键,以及表示指定类型的任意一个按键(如*),另一个参数则是处理这个事件的对应函数。kibo提供了像jquery一样的连续调用,你可以使用kibo.down(…).up(…)这样的调用。

可以使用的键盘包括我们普通使用的a-z这些普通按钮,以及特殊的alt,ctrl等控制按键,也包括表示方向键的"up,down,left等,也包括f1和f12这些功能按键。在调用方法时,可以传递一个或多个按键作为相对应的参数。

当处理按键的事件触发时,我们可以在函数中处理这个事件,也可以直接忽略这个事件。如果你想要调用浏览器默认的处理(如f5调用),则可以在回调函数时直接返回false即可。
在回调函数时,我们可以使用kibo.lastKey方法,来获取在键盘事件触发时所对应的按键信息。此方法将返回相对应的按键名称。或者当不识别这个按键时,将返回undefined。如果给这个方法传递一个按键,如kibo.lastKey("shift"),它将返回在这个按键中,是否按下了指定的键,返回true或false。

继续阅读“使用js(kibo)监听浏览器键盘事件”

安全有效地提升simpleDateFormat性能

    以下为转http://www.thedwick.com/blog/2008/04/simpledateformat-performance-pig/的一篇关于simpleDateformat中使用的一些误区以及怎么样来安全有效地使用simpleDateFormat。在本文中,描述了创造simpleDateFormat的昂贵代价,以及使用静态实例的多线程错误以及同步时的低效问题,并提出一个提升的解决办法。
    全文如下:

    Just yesterday I came across this problem “in the wild” for the third time in my career so far: an application with performance problems creating tons of java.text.SimpleDateFormat instances. So, I have to get this out there: creating a new instance of SimpleDateFormat is incredibly expensive and should be minimized. In the case that prompted this post, I was using JProfiler to profile this code that parses a CSV file and discovered that 50% of the time it took to suck in the file and make 55,000 objects out of it was spent solely in the constructor of SimpleDateFormat. It created and then threw away a new one every time it had to parse a date. Whew!

  “Great,” you think, “I’ll just create one, static instance, slap it in a field in a DateUtils helper class and life will be good.”
    Well, more precisely, life will be good about 97% of the time. A few days after you roll that code into production you’ll discover the second cool fact that’s good to know: SimpleDateFormat is not thread safe. Your code will work just fine most of the time and all of your regression tests will probably pass, but once your system gets under a production load you’ll see the occasional exception.
    “Fine,” you think, “I’ll just slap a ‘synchronized’ around my use of that one, static instance.”
    Ok, fine, you could do that and you’d be more or less ok, but the problem is that you’ve now taken a very common operation (date formatting and parsing) and crammed all of your otherwise-lovely, super-parallel application through a single pipe to get it done.
    What would be better is to use a ThreadLocal variable so you can have your cake and eat it, too:

继续阅读“安全有效地提升simpleDateFormat性能”

JVM对于不同classLoader加载的对象之间default或protected字段的访问限制

    通常对于对象的default及protected访问限制,一般的说法即为只能由同包或子类才能访问。对于同包的类,是可以访问default及protected的字段的。但如下情况除外:
    如果一个由其它途径加载的类尝试访问同一个包中由其它加载器加载的类的受保护或默认级别字段时,将产生一个IllegalAccessError错误,即不允许访问指定的字段。
    即只有相同加载器之间才可以访问受保护字段。

验证程序如下所示:类Foo

public class Foo implements IFoo {
	protected int i = 2;
}

类Foo2将要访问Foo:

public class Foo2 {
	public static void redFoo() {
		Foo f = new Foo();
		System.out.println(f.i);
	}
}

    以下为执行验证的代码:

		MyClassLoader2 myClassLoader2 = new MyClassLoader2(T.class.getClassLoader());
		Class<?> clazz = myClassLoader2.loadClass("m_ylf.study.java.classLoad.Foo2");
//		Class<?> clazz2 = myClassLoader2.loadClass("m_ylf.study.java.classLoad.Foo");
		clazz.getDeclaredMethod("redFoo").invoke(null);

    在以上代码中,将由类加载器单独加载Foo2,而Foo仍由appClassLoader来加载。上面的程序即通过调用Foo2的redFoo方法来读取Foo类的受保护字段,并输出信息。执行结果如下所示:

Exception in thread "main" java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
......
Caused by: java.lang.IllegalAccessError: tried to access field com.m_ylf.study.java.classLoad.Foo.i from class com.m_ylf.study.java.classLoad.Foo2
	at com.m_ylf.study.java.classLoad.Foo2.redFoo(Foo2.java:8)
	... 11 more

    即不能访问该字段,需要注意到的是,在以上的代码中,我们专门注释了使用myClassLoader加载Foo的代码。如果我们取消注释,即也叫myClassLoader来加载Foo,那么结果即能够正确的输出相对应的数字(具体输出结果就不再列出,可以单独测试)。
    需要注意的是,如果Foo中的字段i,本身就是public类型的,则该错误也不会发生。即这个约束只限制在default以及protected字段上。
    这也是为了将一个恶意的代码,加载到虚拟机,来尝试访问本来不能够被访问的信息,如标准java API中的受保护信息(标准API是由java 系统加载器来加载的)。
    以上的叙述取自《深入JVM虚拟机》,由笔者验证得出。

继续阅读“JVM对于不同classLoader加载的对象之间default或protected字段的访问限制”

centos6今日发布(Update–7/7–Coming Soon to a Mirror Near You)

    所最新可靠消息,centos 6经过漫长的等待,今天终于要发布了。现在是美国时间7月7号,所以在中国就需要在7月8号才能发布了。不久,就可以在镜像中找到centos 6的身影了。
    据官方原话:

We got hit by a number of trademark issues on things that needed to be removed before release. This is all cleared 
up now along with a few more last minute bug fixes -- correcting deltarpms behavior, signing updates/ packages, etc.

There are trees pushing out to centos.org internal mirrors now with updated packages and ISO images. This push 
shouldn't take too long since they are relatively small changes to the ISOs. The QA team is going over all the recent 
changes and doing some last-minute checks to be sure the changes didn't break anything else. Once we're all happy 
and the packages finish syncing out to the mirrors, they'll get opened up for external mirrors to sync. Yes, this 
should happen TODAY (my time anyway -- PDT).

    翻译之:

    我们在正式版发布之前已经发现了大量的问题,当然这些问题都已经在过去的一段时间被解决了。比如,收集rpm包的差异化(这是包更新所必须的),以及包签名等。
    现在正在将更新包以及iso镜像发布到内部的centos.org镜像上,不会花太多的时间,因为相比整个发布来说,这只是很小的一部分。QA组正在做最后的检查,以确保不会出现任何的问题。我们很高兴的宣布,只是完成内部同步,就会开放给外部的所有镜像。这些,都将在今天发生(7月7号,美国时间)。

    美国时间比中国差了15个小时,所以今天,7月8号,centos 6将最终发布,希望不要再拖了。