jdk 6 update 26 이 critical patch 로 6월에 나왔네요.

java.lang.ClassCircularityError 관련 에러 패치와 보안 패치가 이루어진 긴급 패치 버전입니다.

 

[결론 : Red hat 계열의 java에서는 영향이 없고, window 플랫폼에서 사용하는 java만 upgrade하면 됩니다.]

 

다음 버전에 대해서는 패치하라고 권고하있습니다.

- JDK & JRE 6 Update 25 버전 및 하위 버전
- JDK 5.0 Update 29 버전 및 하위 버전
- SDK 1.4.2_31 버전 및 하위 버전

 

패치에 대한 내용은 다음과 같습니다.

http://www.oracle.com/technetwork/java/javase/6u26releasenotes-401875.html

 

내용 중에 critical한 요소를 쫓아 들어가보겠습니다.

Bug Fixes

This release contains fixes for security vulnerabilities. For more information, please see Oracle Java SE Critical Patch Update advisory.

 

 

어떤 보안 요소가 패치되었나 들어가보니.아래 링크가 뜹니다.

http://www.oracle.com/technetwork/topics/security/javacpujune2011-313339.html

 

Oracle Java SE Risk Matrix


CVE# Component Protocol Sub-
component
Remote Exploit without Auth.? CVSS VERSION 2.0 RISK (see Risk Matrix Definitions) Supported Versions Affected Notes
Base Score Access Vector Access Complexity Authen-
tication
Confiden-
tiality
Integrity Avail-
ability
CVE-2011-0862 Java Runtime Environment Multiple 2D Yes 10.0 Network Low None Complete Complete Complete 6 Update 25 and before, 5.0 Update 29 and before, 1.4.2_31 and before See Note 1
CVE-2011-0873 Java Runtime Environment Multiple 2D Yes 10.0 Network Low None Complete Complete Complete 6 Update 25 and before, and 5.0 Update 29 and before See Note 2
CVE-2011-0815 Java Runtime Environment Multiple AWT Yes 10.0 Network Low None Complete Complete Complete 6 Update 25 and before, 5.0 Update 29 and before, 1.4.2_31 and before See Note 3
CVE-2011-0817 Java Runtime Environment Multiple Deployment Yes 10.0 Network Low None Complete Complete Complete 6 Update 25 and before on Windows See Note 3
CVE-2011-0863 Java Runtime Environment Multiple Deployment Yes 10.0 Network Low None Complete Complete Complete 6 Update 25 and before See Note 3
CVE-2011-0864 Java Runtime Environment Multiple HotSpot Yes 10.0 Network Low None Complete Complete Complete 6 Update 25 and before, 5.0 Update 29 and before, 1.4.2_31 and before See Note 3
CVE-2011-0802 Java Runtime Environment Multiple Sound Yes 10.0 Network Low None Complete Complete Complete 6 Update 25 and before, 5.0 Update 29 and before, 1.4.2_31 and before See Note 2
CVE-2011-0814 Java Runtime Environment Multiple Sound Yes 10.0 Network Low None Complete Complete Complete 6 Update 25 and before, 5.0 Update 29 and before, 1.4.2_31 and before See Note 2
CVE-2011-0871 Java Runtime Environment Multiple Swing Yes 10.0 Network Low None Complete Complete Complete 6 Update 25 and before, 5.0 Update 29 and before, and 1.4.2_31 and before See Note 3
CVE-2011-0786 Java Runtime Environment Multiple Deployment Yes 7.6 Network High None Complete Complete Complete 6 Update 25 and before on Windows See Note 3
CVE-2011-0788 Java Runtime Environment Multiple Deployment Yes 7.6 Network High None Complete Complete Complete 6 Update 25 and before on Windows See Note 3
CVE-2011-0866 Java Runtime Environment Multiple Java Runtime Environment Yes 7.6 Network High None Complete Complete Complete 6 Update 25 and before, 5.0 Update 29 and before, 1.4.2_31 and before on Windows See Note 3
CVE-2011-0868 Java Runtime Environment Multiple 2D Yes 5.0 Network Low None Partial None None 6 Update 25 and before See Note 2
CVE-2011-0872 Java Runtime Environment Multiple NIO Yes 5.0 Network Low None None None Partial+ 6 Update 25 and before, 5.0 Update 29 and before, 1.4.2_31 and before for Windows See Note 4
CVE-2011-0867 Java Runtime Environment Multiple Networking Yes 5.0 Network Low None Partial None None 6 Update 25 and before, 5.0 Update 29 and before, 1.4.2_31 and before See Note 3
CVE-2011-0869 Java Runtime Environment Multiple SAAJ Yes 5.0 Network Low None Partial None None 6 Update 25 and before See Note 3
CVE-2011-0865 Java Runtime Environment Multiple Deserialization Yes 2.6 Network High None None Partial None 6 Update 25 and before, 5.0 Update 29 and before, 1.4.2_31 and before See Note 3
 

 

Notes:

  1. Fix addresses multiple instances of this vulnerability.
    Applies to client and server deployments of Java. This vulnerability can be exploited through Untrusted Java Web Start applications and Untrusted Java applets. It can also be exploited by supplying data to APIs in the specified Component without using untrusted Java Web Start applications or untrusted Java applets, such as through a web service.
  2. Applies to client and server deployments of Java. This vulnerability can be exploited through Untrusted Java Web Start applications and Untrusted Java applets. It can also be exploited by supplying data to APIs in the specified Component without using untrusted Java Web Start applications or untrusted Java applets, such as through a web service.
  3. Applies to client deployments of Java only. This vulnerability can be exploited only through Untrusted Java Web Start applications and Untrusted Java applets. (Untrusted Java Web Start applications and untrusted applets run in the Java sandbox with limited privileges.)
  4. Applies to server deployments of Java. This vulnerability can only be exploited by supplying data to APIs in the specified Component without using Untrusted Java Web Start applications or Untrusted Java applets, such as through a web service.

 

대부분이 webstart와 관련된 것이라 큰 이슈가 없지만, 이 중에 NIO 컴포넌트쪽이 이슈가 있군요.

 

CVE-2011-0872 Java Runtime Environment Multiple NIO Yes 5.0 Network Low None None None Partial+ 6 Update 25 and before, 5.0 Update 29 and before, 1.4.2_31 and before for Windows See Note 4

 

 

원래 이름은 이거입니다.

CVE-2011-0872 OpenJDK: non-blocking sockets incorrectly selected for reading (NIO, 6213702)

 

정확한 내용을 확인해보니, Red hat 계열의 java에서는 영향이 없고, window 플랫폼에서 사용하는 java에 영향이 있다고 합니다.

https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2011-0872 

http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2011-0872

Posted by 김용환 '김용환'
TAG Java

댓글을 달아 주세요

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6948803


jdk 19에서 아래와 같은 문제가 밸생할 수 있다.
algorithm check failed: MD2withRSA is disabled

http://kr.forums.oracle.com/forums/thread.jspa?threadID=1237743&start=0&tstart=0

토의 내용
http://mail.openjdk.java.net/pipermail/jdk6-dev/2010-May/001609.html
 


Bug ID: 6948803
Votes 0
Synopsis CertPath validation regression caused by SHA1 replacement root and MD2 disable feature
Category java:classes_security
Reported Against
Release Fixed 6u21(b05), 7(b97) (Bug ID:2193256)
State 10-Fix Delivered, bug
Priority: 2-High
Related Bugs 6861062 , 6904162 , 2194455 , 7017668
Submit Date 30-APR-2010
Description
In 6u19, several VeriSign MD2/MD5 root certificates were replaced with stronger SHA1 versions (same key, stronger signature). Some customers using certificates issued from the VeriSign PCA 3 root have been reporting problems that cause their existing certificate chains to be rejected by the JRE because the certificate chain still includes the weaker MD2 root and we disabled MD2 support in 6u17.

The problem is that our certpath validation implementation adds the SHA1 root to the beginning of the chain but does not replace the existing MD2 root. So the chain includes both roots, first the SHA1, then the MD2 and then the rest of the chain. The chain is rejected because the MD2 root is treated as an intermediate CA cert. 

It seems our implementation should instead replace the MD2 root with the stronger SHA1 root before validating the chain.
Posted Date : 2010-04-30 13:38:51.0
Work Around
Their are a few ways to workaround the issue. For TLS, the server's certificate chain can be reconfigured so that either the MD2 root certificate is not included in the chain (including the root cert is optional in TLS), or it should be replaced with the SHA1 root certificate.

For code signing, you can re-sign the jar and include a chain with the SHA1 root instead of the MD2 root, or a chain without the root cert.
Evaluation
Fixed. A cert with the same issuer and public key as a trusted anchor is removed from the chain.
Posted Date : 2010-05-18 10:43:09.0
Comments
   
  Include a link with my name & email   
 


PLEASE NOTE: JDK6 is formerly known as Project Mustang
 


oracle java 6 update 21에서 패치되었다.
http://www.oracle.com/technetwork/java/javase/bugfixes6u21-156339.html
6948803  java classes_security CertPath validation regression caused by SHA1 replacement root and MD2 disable feature

Posted by 김용환 '김용환'
TAG Bug, Java

댓글을 달아 주세요


자바(java)에서 특정 로직이 얼마나 소요되는지 체크를 하는 방법을 소개한다.



속도체크
View more presentations from knight1128.





1. jdk에서 제공하는 System 클래스의 currentTimeMillis() 메소드를 이용해서 확인할 수 있다.

예제
long startTime = System.currentTimeMillis();
Thread.sleep(1000);
long estimatedTime = System.currentTimeMillis() - startTime;
System.out.println("took " + estimatedTime + " ms");

결과값은 밀리세컨드(ms)로 다음과 같다.
took 1000 ms


2. jdk에서 제공하는 System 클래스의 nanoTime() 메소드를 이용해서 확인할 수 있다. 아주 정확한 시간을 측정할 때 많이 활용한다.

예제
long time1 = System.nanoTime();
Thread.sleep(1000);
long time2 = System.nanoTime();
long timeSpent = time2 - time1;
System.out.println("took " + timeSpent + " ns");

결과값은 nano 값으로 나온다.
took 1000232514 ns

3. Common-lang의 StopWatch 클래스를 이용한다. (commons-lang 2.3)

예제
import org.apache.commons.lang.time.StopWatch;

StopWatch stopWatch = new StopWatch();
stopWatch.reset();
stopWatch.start();
Thread.sleep(2000);
stopWatch.stop();
System.out.println(stopWatch.toString());
  
stopWatch.reset();
stopWatch.start();
Thread.sleep(5000);
stopWatch.stop();
System.out.println(stopWatch.toString());
  
stopWatch.reset();
stopWatch.start();
Thread.sleep(3000);
stopWatch.stop();
System.out.println(stopWatch.toString());


start를 하기전에 반드시 reset()를 해야 한다. 그 이유는 Common-lang의 StopWatch 클래스는 내부적으로 status를 가지고 있다. 이 부분에 대해서 약간 신경써야 한다. 자세한 것은 뒤에서 다시 설명한다.

결과값은 다음과 같다.

0:00:02.000
0:00:05.000
0:00:03.000


4. Spring core lib에 있는 util성 StopWatch 클래스를 이용한다. (Spring 3.0.x)

예제
import org.springframework.util.StopWatch;

...
StopWatch stopWatch = new StopWatch("Stop Watch");
stopWatch.start("initializing");
Thread.sleep(2000);
stopWatch.stop();
System.out.println("took " + stopWatch.getLastTaskTimeMillis() + " ms");
stopWatch.start("processing");
Thread.sleep(5000);
stopWatch.stop();
System.out.println("took " + stopWatch.getLastTaskTimeMillis() + " ms");
  
stopWatch.start("finalizing");
Thread.sleep(3000);
stopWatch.stop();
System.out.println("took " + stopWatch.getLastTaskTimeMillis() + " ms");
  
System.out.println(stopWatch.toString());
System.out.println();
System.out.println(stopWatch.prettyPrint());

결과 화면
took 2000 ms
took 5000 ms
took 3001 ms
StopWatch 'Stop Watch': running time (millis) = 10001; [initializing] took 2000 = 20%; [processing] took 5000 = 50%; [finalizing] took 3001 = 30%
StopWatch 'Stop Watch': running time (millis) = 10001
-----------------------------------------
ms     %     Task name
-----------------------------------------
02000  020%  initializing
05000  050%  processing
03001  030%  finalizing


얼마나 소요되었는지, 그동안의 관련정보를 계속 모아서, Task 별로 모아 정보를 출력한다.

5. 그냥 인터넷에서 남들이 만든 StopWatch를 찾아서 copy&paste한다.

http://www.devdaily.com/blog/post/java/stopwatch-class-that-can-be-used-for-timings-benchmarks



* Commons-lang의 StopWatch와 Spring Util의 StopWatch를 간단히 비교하였다.

 

Commons-lang StopWatch 클래스

Spring util StopWatch 클래스

FQN

org.apache.commons.lang.time.StopWatch

org.springframework.util.StopWatch

메모리

경량화

Commons-lang Stopwatch보다는 메모리 조금 더 소요 (Task로 관리)

사용성

O

<OO (통계를 내주니까..)

기본 메소드

Start(), stop(), reset(), suspend(), resume()

Start(),stop()

이름(id)

X

O

Running status

Unstarted, running, stopped, suspended

 

상태가 있기 때문에 규칙이 있음

 

you cannot now call stop before start, resume before suspend or unsplit before split.

 

1. split(), suspend(), or stop() cannot be invoked twice

2. unsplit() may only be called if the watch has been split()

3. resume() may only be called if the watch has been suspend()

4. start() cannot be called twice without calling reset()

Running, not running

Split

기능 :시계에서처럼 split 기능

 

Status : Unsplit, split

 

Split(), Unsplit(), getSplitTime(), toSplitString()

X

Start task name

X

O

Print

O

toString()

O

toString()

shortSummary()

prettyPrint

누적시간을 기준으로 출력

Keeping track

X

O

setKeepTaskList(boolean keepTaskList)

디폴트값은 true

isRunning

X

O

isRunning()

Last time

X

O

getLastTaskTimeMillis()

Total time

X

O

getTotalTimeSeconds()

getTotalTimeMillis()

Task count

X

O

getTaskCount()






추가 - guava stopwatch 


예제

import java.util.concurrent.TimeUnit;

import org.junit.Test;

import com.google.common.base.Stopwatch;

public class GuavaTest {

@Test
public void test() {

Stopwatch 
stopwatch = Stopwatch.createStarted();

try {
Thread.sleep(1000);
catch (InterruptedException e) {
e.printStackTrace();
}

System.
out.println("Elapsed time : " + stopwatch);
System.
out.println("Elapsed time (milliseconds) : " + stopwatch.elapsed(TimeUnit.MILLISECONDS));
System.
out.println("Elapsed time (microseconds) : " + stopwatch.elapsed(TimeUnit.MICROSECONDS));
System.
out.println("Elapsed time (nanoseconds) : " + stopwatch.elapsed(TimeUnit.NANOSECONDS));
                
                                stopwatch.stop();
}



결과

Elapsed time : 1.001 s

Elapsed time (nanoseconds) : 1004995000

Elapsed time (microseconds) : 1005043

Elapsed time (Milliseconds) : 1005


'general java' 카테고리의 다른 글

구글 프로토콜 버퍼 (Google Protocl Buffer)  (0) 2011.08.03
Hiberate 4  (0) 2011.07.15
특정 로직에 대해서 성능 확인 (속도 체크) - stopwatch  (0) 2011.07.08
DBCP connection 정리  (0) 2011.07.05
Spring Batch - MSSQL 채번  (0) 2011.04.07
Spring Batch retry 예제들  (0) 2011.04.06
Posted by 김용환 '김용환'

댓글을 달아 주세요

java -server

java core 2010. 8. 19. 16:06

jdk1.5 부터는 메모리 2G이상, cpu 2개이상 있으면, 자동으로 server-class로 판별하고 자동으로 -server로 jvm을 실행하게 된다.

리눅스 서버는 대부분이 cpu2개이상, 메모리 2G이상이면, -server 옵션 안써도 됨~

 

 

http://java.sun.com/docs/hotspot/gc5.0/ergo5.html

 

In the J2SE platform version 5.0 a class of machine referred to as a server-class machine has been defined as a machine with

- 2 or more physical processors

- 2 or more Gbytes of physical memory

 

On server-class machines by default the following are selected.

- Throughput garbage collector

- Heap sizes

- initial heap size of 1/64 of physical memory up to 1Gbyte

- maximum heap size of ¼ of physical memory up to 1Gbyte

- Server runtime compiler

'java core' 카테고리의 다른 글

java checked Exception에 대한 고찰  (0) 2010.10.01
Java option 관련  (0) 2010.08.31
java -server  (0) 2010.08.19
G1 알고리즘 공부  (0) 2010.08.09
JDK 1.6.0 update 21 때문에 Eclipse 문제 발생  (0) 2010.08.09
Random과 SecureRandom의 차이  (0) 2010.08.05
Posted by 김용환 '김용환'

댓글을 달아 주세요

JMX reference

java core 2009. 4. 29. 21:07

http://java.sun.com/docs/books/tutorial/jmx/
http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html#gdjou
http://java.sun.com/javase/6/docs/technotes/guides/management/mxbeans.html
http://java.sun.com/j2se/1.5.0/docs/guide/jmx/index.html
http://blog.naver.com/PostView.nhn?blogId=pecman&logNo=110015624171
http://www.ibm.com/developerworks/library/j-rtm1/index.html
https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_JCP-Site/en_US/-/USD/ViewFilteredProducts-SimpleBundleDownload
http://lemonfish.egloos.com/4253102
http://www.chicdesign.co.kr/java/JMX/overview/appendixA.htm#wp1002189
http://chanwook.tistory.com/575
http://link.allblog.net/1228782/http://hanjava.net/call-151/2006/08/21/java%EB%A1%9C-physical-memory-%ED%81%AC%EA%B8%B0-%EC%95%8C%EC%95%84%EB%82%B4%EA%B8%B0/
http://link.allblog.net/14933961/http://judy98.tistory.com/entry/Creating-a-Custom-JMX-Client
http://link.allblog.net/15921220/http://adeveloper.tistory.com/107
http://link.allblog.net/12312721/http://bcho.tistory.com/entry/WebLogic%EC%97%90%EC%84%9C-Inflight-Transaction%EC%A7%84%ED%96%89%EC%A4%91%EC%9D%B8-%ED%8A%B8%EB%A0%8C%EC%A0%9D%EC%85%98-%EC%83%81%ED%83%9C-%EB%AA%A8%EB%8B%88%ED%84%B0%EB%A7%81-%ED%95%98%EA%B8%B0
http://weblogs.java.net/blog/emcmanus/archive/2007/05/making_a_jmx_co_1.html
http://weblogs.java.net/blog/emcmanus/
http://marxsoftware.blogspot.com/2008/08/remote-jmx-connectors-and-adapters.html
http://weblogs.java.net/blog/emcmanus/archive/performance/index.html
http://blogs.sun.com/jmxnetbeans/
http://forums.sun.com/forum.jspa?forumID=537
http://java.sun.com/javase/technologies/core/mntr-mgmt/javamanagement/download.jsp

MXBEAN
http://weblogs.java.net/blog/emcmanus/archive/2006/02/what_is_an_mxbe.html
http://java.sun.com/javase/technologies/core/mntr-mgmt/javamanagement/
http://weblogs.java.net/blog/emcmanus/archive/2006/11/a_real_example.html
http://blogs.sun.com/jmxetc/entry/how_to_retrieve_remote_jvm
http://blogs.sun.com/joel/entry/easily_modifying_and_rebuilding_jmx

'java core' 카테고리의 다른 글

How to get object size in java.  (0) 2009.05.29
How to get List comparator using Comparator class.  (0) 2009.05.13
JMX reference  (0) 2009.04.29
Effective Java Reload  (0) 2009.04.29
Rounding(Scaling) x postion of decimal point  (0) 2009.04.29
How to get cpu usage in java.  (0) 2009.04.29
Posted by 김용환 '김용환'
TAG Java, JMX

댓글을 달아 주세요

BCEL in Java 6

eclipse 2009. 4. 29. 20:15


Java 6 have bcel packages, so I made interesting code to print "Hello World" every first-experience java developers have to meet.
There are no library have to include. That's my favorite!! 

BCEL tutorial is below web site.
http://jakarta.apache.org/bcel/manual.html


 



import com.sun.org.apache.bcel.internal.Constants;
import com.sun.org.apache.bcel.internal.generic.ArrayType;
import com.sun.org.apache.bcel.internal.generic.ClassGen;
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
import com.sun.org.apache.bcel.internal.generic.InstructionFactory;
import com.sun.org.apache.bcel.internal.generic.InstructionList;
import com.sun.org.apache.bcel.internal.generic.MethodGen;
import com.sun.org.apache.bcel.internal.generic.ObjectType;
import com.sun.org.apache.bcel.internal.generic.PUSH;
import com.sun.org.apache.bcel.internal.generic.Type;

public class SimpleHelloWorldBuilder {
public static void main(String[] args) throws Exception {
// public HellowWorld extends java.lang.Object
ClassGen classGen = new ClassGen("HelloWorld", "java.lang.Object", "", Constants.ACC_PUBLIC
| Constants.ACC_SUPER, null);
ConstantPoolGen constantPoolGen = classGen.getConstantPool();
InstructionList instructionList = new InstructionList();

// public static void main
MethodGen methodGen = new MethodGen(Constants.ACC_PUBLIC | Constants.ACC_STATIC, Type.VOID,
// (String[] args)
new Type[] {new ArrayType(Type.STRING, 1)}, new String[] {"args"}, "main", "HelloWorld", instructionList, constantPoolGen);

InstructionFactory instructionFactory = new InstructionFactory(classGen);
classGen.addEmptyConstructor(Constants.ACC_PUBLIC);
// System.out.println
ObjectType printStream = new ObjectType("java.io.PrintStream");
instructionList.append(instructionFactory.createFieldAccess("java.lang.System", "out", printStream, Constants.GETSTATIC));
// "Hello world!!"
instructionList.append(new PUSH(constantPoolGen, "Hello World!!"));
instructionList.append(instructionFactory.createInvoke("java.io.PrintStream", "println", Type.VOID,
new Type[] {Type.STRING}, Constants.INVOKEVIRTUAL));

classGen.addMethod(methodGen.getMethod());
instructionList.dispose();

classGen.getJavaClass().dump("build/HelloWorld.class");
}
}



After running this class, I can find "build/HelloWorld.class". 
By using jad, I can see the decompiled class.
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   

import java.io.PrintStream;

public class HelloWorld
{

    public HelloWorld()
    {
    }

    public static void main(String args[])
    {
        System.out.println("Hello World!!");
    }
}


Posted by 김용환 '김용환'
TAG bcel, Java

댓글을 달아 주세요

Effective Java Reload

java core 2009. 4. 29. 19:23

screen
http://www.parleys.com/display/PARLEYS/Home#slide=1;title=Effective%20Java%20Reloaded;talk=18317360

Java one in 2006
http://developers.sun.com/learning/javaoneonline/j1sessn.jsp?sessn=TS-1512&yr=2006&track=coreplatform

http://developers.sun.com/learning/javaoneonline/2006/coreplatform/TS-1512.pdf

'java core' 카테고리의 다른 글

How to get List comparator using Comparator class.  (0) 2009.05.13
JMX reference  (0) 2009.04.29
Effective Java Reload  (0) 2009.04.29
Rounding(Scaling) x postion of decimal point  (0) 2009.04.29
How to get cpu usage in java.  (0) 2009.04.29
How to get hostname in http url in Java  (0) 2009.04.28
Posted by 김용환 '김용환'
TAG Java

댓글을 달아 주세요



Getting cpu usage in java instance, that limits in executing java virtual machine, not os.


Have a look at the java class sun.tools.jconsole.SummaryTab.java in open JDK7 or source in web.(http://www.docjar.com/html/api/sun/tools/jconsole/SummaryTab$Result.java.html)

If you know JConsole, you know that cpu usages graph. that source is below.

  354       private static class CPUOverviewPanel extends OverviewPanel {
  355           private long prevUpTime, prevProcessCpuTime;
  356   
  357           CPUOverviewPanel() {
  358               super(getText("CPU Usage"), cpuUsageKey, cpuUsageName, Plotter.Unit.PERCENT);
  359               getPlotter().setDecimals(CPU_DECIMALS);
  360           }
  361   
  362           public void updateCPUInfo(Result result) {
  363               if (prevUpTime > 0L && result.upTime > prevUpTime) {
  364                   // elapsedCpu is in ns and elapsedTime is in ms.
  365                   long elapsedCpu = result.processCpuTime - prevProcessCpuTime;
  366                   long elapsedTime = result.upTime - prevUpTime;
  367                   // cpuUsage could go higher than 100% because elapsedTime
  368                   // and elapsedCpu are not fetched simultaneously. Limit to
  369                   // 99% to avoid Plotter showing a scale from 0% to 200%.
  370                   float cpuUsage =
  371                       Math.min(99F,
  372                                elapsedCpu / (elapsedTime * 10000F * result.nCPUs));
  373   
  374                   getPlotter().addValues(result.timeStamp,
  375                                   Math.round(cpuUsage * Math.pow(10.0, CPU_DECIMALS)));
  376                   getInfoLabel().setText(getText(cpuUsageFormat,
  377                                                  String.format("%."+CPU_DECIMALS+"f", cpuUsage)));
  378               }
  379               this.prevUpTime = result.upTime;
  380               this.prevProcessCpuTime = result.processCpuTime;
  381           }
  382       }



So. I made my own class to get java-cpu usage.
private void _getJavaRuntime() {
OperatingSystemMXBean osbean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
RuntimeMXBean runbean = (RuntimeMXBean) ManagementFactory.getRuntimeMXBean();
int nCPUs = osbean.getAvailableProcessors();
long prevUpTime = runbean.getUptime();
long prevProcessCpuTime = osbean.getProcessCpuTime();
try {
Thread.sleep(500);
} catch (Exception e) { }
osbean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
long upTime = runbean.getUptime();
long processCpuTime = osbean.getProcessCpuTime();
if (prevUpTime > 0L && upTime > prevUpTime) {
long elapsedCpu = processCpuTime - prevProcessCpuTime;
long elapsedTime = upTime - prevUpTime;
javacpu = Math.min(99F, elapsedCpu / (elapsedTime * 10000F * nCPUs));
} else {
javacpu = 0.001;
}
uptime = runbean.getUptime(); 
}


'java core' 카테고리의 다른 글

Effective Java Reload  (0) 2009.04.29
Rounding(Scaling) x postion of decimal point  (0) 2009.04.29
How to get cpu usage in java.  (0) 2009.04.29
How to get hostname in http url in Java  (0) 2009.04.28
G1 garbage collection  (0) 2009.04.28
Implementing equals method of collections classes  (0) 2009.04.27
Posted by 김용환 '김용환'
TAG Java

댓글을 달아 주세요

Jad 사용법

general java 2009. 4. 10. 00:23
1. jad 사용법
특정 디렉토리에 있는 모든 클래스 파일을 모두 java 소스로 변경한다.
D:\javasrc\ojdbc14>jad -r -d src -sjava oracle\**\*.class

2. 클래스 파일 자바로 보기
클래스 파일 더블클릭하면 자동으로 노트패드로 보여주고, 노트패드 종료하면 jad 파일 삭제한다.
1) jad를 다운받고, jad.exe가 실행이 되도록 그 디렉토리를 path에 추가한다.

2) 그 디렉토리에 jad.bat를 아래와 같이 생성한다.

@echo off
jad -o -d. %*
notepad %~n1.jad
del %~n1.jad

3) class 파일들의 속성에 위의 jad.bat 프로그램을 연동시킬 수 있도록 한다. class 파일에 대해서 더블클릭하면 자동으로 노트패드가 뜨는 것을 확인할 수 있다.
 


'general java' 카테고리의 다른 글

java sources for ojdbc  (0) 2009.04.17
중요한 DBCP 설정 공부  (0) 2009.04.10
Jad 사용법  (0) 2009.04.10
JMX 개발중 POJO를 이용하기  (0) 2009.03.31
jdk 5,6 클래스를 jdk 3,4에서 실행하기  (0) 2009.03.30
JMX에서의 Internalization  (0) 2009.03.25
Posted by 김용환 '김용환'

댓글을 달아 주세요

Retrotranslator(http://retrotranslator.sourceforge.net/)를 사용하면 된다.
Posted by 김용환 '김용환'

댓글을 달아 주세요