`

java thread / process / thread runnable / thread sleep / thread run

    博客分类:
  • Java
阅读更多

 

Java Thread &Memory Note

http://sslaowan.iteye.com/blog/1450671

 

top -p pid -H  see jvm thread on linux.I read the source of the jvm,and found jvm create threads  using NPTL under Linux2.6+.

pstree pid  see stat jvm count of thread.

 

jmap -histo vmid | jmap -histo:live vmid

jstack vmid

 

为什么会"well-known file is not secure" ?

http://lkf520java.iteye.com/blog/1560686

http://stackoverflow.com/questions/9100149/jstack-well-known-file-is-not-secure?rq=1

最近一段时间经常使用JDK自带工具jmap和jstack来dump JVM heap和JVM 线程栈的log来分析问题,执行这两个命令当时让我最摸不着头脑的就是碰到这个问题:well-known file is not secure

eg:

 

上网google了一把,在stackoverflow上找到答案:http://stackoverflow.com/questions/9100149/jstack-well-known-file-is-not-secure?rq=1,大概意思是: 我们可以在机器上找到 /tmp/hsperfdata_$USER/$PID一个这样的文件,当我们执行jmap或者jstack出现上叙信息时,先检查执行该命令的用户是否和hsperfdata_$USER这个文件所属的用户一致,如果不一致,切换至成一致再执行即可。

 

nmon_x86_64_rhel54 -f -t -s 10 -c 1000

 

 

 

Bookmark:

Virtual VM http://www.longtask.com/blog/?p=465

JConsole http://simpleframework.net/blog/v/16528.html

JAVA 进程异常高的 CPU 占用率 http://blog.csdn.net/subchen/article/details/5801072

Java多线程编程总结 http://lavasoft.blog.51cto.com/62575/27069

Linux基础(7)-linux管理监控(pstree,top) http://www.lifeba.org/arch/linux_pstree_top.html

top命令中的交互命令,shift+p按CPU排序,shift+m按内存使用排序,shift+t 按CPU用时排序,shift+n按PID排序   http://blog.163.com/xychenbaihu@yeah/blog/static/1322296552012017105732762/

java:找出占用CPU资源最多的那个线程(HOW TO)  http://wenyue.me/blog/382

java 中关于信号的处理在linux下的实现  http://blog.csdn.net/raintungli/article/details/7178472

 

sdfsfd

 

package com.javaeye.lindows.thread;

public class YieldTest implements Runnable {
	
	public void run() {
		synchronized(this) {
			for(int i=0;i<50;i++) {
				if(i==25) {
					try {
						wait(5000);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				System.out.println(i);			
			}
			
		}
			
		
	}
	
	public synchronized void sayHello() throws InterruptedException {
		
		for(int i=0;i<20;i++) {
			if(i==10) {
				Thread.yield();
				
			}
			System.out.println("hello:"+i);
		}	
		notifyAll();
	}
	
	public static void main(String[] args) throws InterruptedException {
		
		YieldTest yt = new YieldTest();
		Thread t = new Thread(yt);
		t.start();
		Thread.yield();
		yt.sayHello();
		
	}

}

 

sadfff

控制任务管理器CPU曲线(Java实现)

http://blog.csdn.net/taizhoufox/article/details/4664734

如何让windows任务管理器实现你想要的曲线呢,下午查了下资料,自己动手实践了一下。思路很简单,CPU使用记录的数据来源就是CPU的使用率,只要让它一会忙(执行循环),一会闲(sleep),最终得到(每周期执行时间/一个周期)就能得到一个数字,将这些离散的数字连接起来,就是曲线图了。

画直线和画正弦都还好,只是后来到了加速图像显示的时候,出现一个图形如下图

http://dl2.iteye.com/upload/attachment/0103/4781/fb66a0f1-940f-3c29-b3b9-f7cb0f7b9d05.jpg

 

很是奇怪,到底是什么原因呢?肯定是跟任务管理器CPU曲线的刷新率相关的。

假设刷新时间为1S,

那么第三个程序在的flushtime在小于1000的情况下可以起到控制图像的作用(小于1000,执行的时间和sleep的时间都会乘上相同的系数,最终的比例还是不会变的)。

如果他它大于1000的话,那么在一段时间,它将得到几个相同的点,然后由于短暂的突变(比如执行时间很长,sleep时间很短,则会出现波谷,执行时间很短,sleep时间很长,则会出现波峰),它又将回到回来的位置,但是总体的形状还是保持原来的基本样式,这应该就能解释上面的图形了吧。。。。 

 

以下是java代码

 

 

package system;
public class CpuUsage {
	
	public static void drawLine(){	
		int usage = 700;
		System.out.println("Test Begins...");		
		while(true){		
			long start = System.currentTimeMillis();
			while(System.currentTimeMillis() - start < usage );
			try{
				Thread.sleep(1000-usage);
			}catch(Exception e){
				System.out.print(e);
			}		
		}
	}
	public static void drawSin(){
		double x = Math.PI / 2;	
		while(true){
			//下面这一句+1是因为sinx可能为负数,最大为-1,加上1的话就保证为正了
			//*0.5是应为加1之后,最大数可能达到2,为了限制在1以内,所以*0.5
			long usage = (long)((Math.sin(x)+1)*0.5*1000);
			System.out.println(usage);
			long start =  System.currentTimeMillis();
			while(System.currentTimeMillis() - start < usage);
			try{
				Thread.sleep(1000 - usage);
			}catch(Exception e){
				System.out.print(e);
			}
			x += 0.1;
		}
	}	
	public static void drawSinSpeedup(){
		double x = Math.PI / 2;	
		//加入了刷新时间,可以调控曲线弯曲程度
		int flushtime = 5000;
		while(true){
			long usage = (long)((Math.sin(x)+1)*0.5*flushtime);
			System.out.println(usage);
			long start =  System.currentTimeMillis();
			while(System.currentTimeMillis() - start < usage);
			try{
				Thread.sleep(flushtime - usage);
			}catch(Exception e){
				System.out.print(e);
			}
			x += 0.1;
		}
	}
} 

 

 

 

end

  • 大小: 95.5 KB
  • 大小: 8.9 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics