`
suifeng
  • 浏览: 176335 次
  • 性别: Icon_minigender_1
  • 来自: 天津
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
jmx实例
 public class WebServer implements WebServerMBean { ... }

  ...

  WebServer ws = new WebServer(...);
  MBeanServer server = ManagementFactory.getPlatformMBeanServer();
  server.registerMBean(ws, new ObjectName("myapp:type=webserver,name=Port 8080"));
apache configuration apache commons
//动态加载
XMLConfiguration config = new XMLConfiguration(filename);
config.setReloadingStrategy(new FileChangedReloadingStrategy());

//复合支持
 CompositeConfiguration config = new CompositeConfiguration(); 
 config.addConfiguration(new SystemConfiguration()); 
 config.addConfiguration(new PropertiesConfiguration("cfgtest/test1.properties")); 

//变量支持 .properties文件
application.title = ${application.name} ${application.version}  

//注意路径默认指向的是classpath的根目录  
Configuration config = new PropertiesConfiguration("te/test.properties");  
String ip=config.getString("ip");  
int port=config.getInt("port");  
String title=config.getString("application.title");  
//再举个Configuration的比较实用的方法吧,在读取配置文件的时候有可能这个键值对应的值为空,那么在下面这个方法中  
//你就可以为它设置默认值。比如下面这个例子就会在test.properties这个文件中找id的值,如果找不到就会给id设置值为123  
//这样就保证了java的包装类不会返回空值。虽然功能很简单,但是很方便很实用。  
Integer id=config.getInteger("id", new Integer(123));  
//如果在properties 文件中有如下属性keys=cn,com,org,uk,edu,jp,hk  
//可以实用下面的方式读取:  
String[] keys1=config.getStringArray("keys");  
    List keys2=config.getList("keys");  
      
虚拟机异常信息
Java HotSpot(TM) Client VM warning: Attempt to allocate stack guard pages failed.

Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

Exception java.lang.OutOfMemoryError: requested 1048592 bytes for promotion. Out of swap space?

Error occurred during initialization of VM
Could not reserve enough space for object heap

Exception java.lang.OutOfMemoryError: requested 10223616 bytes for heap expansion. Out of swap space?

Java HotSpot(TM) Client VM warning: Attempt to unguard stack red zone failed.

An unrecoverable stack overflow has occurred.
Could not reserve enough space for object heap

Error occurred during initialization of VM
Could not reserve enough space for object heap

Exception in thread "CompilerThread1" java.lang.OutOfMemoryError: requested 88888 bytes for Chunk::new. Out of swap space?
1261

虚拟机经验知识
虚拟机经验知识

1, 虚拟机内存中分为堆和栈
	1.1 堆对应的虚拟机参数是 -Xms(初始大小), -Xmn(最小), -Xmx(最大)
	1.2 栈对应的参数是-Xss
2, 栈是预定式申请(在任务管理器可能看不出大小), 申请的大小是 -Xss值的两倍(默认512k), 如果内存不足, 就会报Caused by: java.lang.OutOfMemoryError: unable to create new native thread
3, 堆是使用使申请(在任务管理器中看到处理), 如果不能申请就会报java.lang.OutOfMemoryError: Java heap space
4, 最大线程估算, 未启动java之前的剩余内存M, 运行java过程中可用内存LM内存(M-JM), java运行占用的内存JM(最大值-Xmx值), 
		每个线程占用堆大小Sd, Ss每个线程栈大小(虚拟机参数-Xss设置的值,默认值256k~512k之间一个数, 测试出来了(265+64=319k))
		min{LM/(2*Ss), JM/Sd}
		

jsp占用 250k左右大小
tomcat行
一次请求 占用 160k左右大小
apache安装负载均衡模块 apache
cd /root/Desktop/httpd-2.2.19/modules/proxy
/usr/local/apache2/bin/apxs  -c  -i -a mod_proxy.c proxy_util.c
/usr/local/apache2/bin/apxs  -c  -i -a mod_proxy_http.c proxy_util.c
/usr/local/apache2/bin/apxs  -c  -i -a mod_proxy_balancer.c proxy_util.c
定时从user1的table1导入user2的table2中的例子
-------------------------------------
--- 定时从user1的table1导入user2的table2中的例子
------------------------------------

----创建一个存储过程用于导入
/
create or replace procedure table1_into_table2
as
begin
	---user1的table1导入user2的table2中的例子
  insert into user2.table2
  select * from user1.table1
  where user1.table1.id not in (select id from user2.table2)   ---避免重复
  ;
  commit;
end;

----创建一个 job 定时执行导入 
/
declare 
jobno number;
begin

dbms_job.submit(jobno,
'table1_into_table2;',   ---存储过程名称
sysdate,              ---从现在开始
'sysdate+1/1440');    ---每隔一分钟执行一次, 
commit;
end;
/


----参考(里面包含, 更详细的时间周期)
---http://hi.baidu.com/4shop/blog/item/7b7e7809ebacf3c83bc763bc.html 
线程练习 线程
package i.study.thread.concurrence;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.CountDownLatch;

/**
 * 
 * @author yanchangyou
 *  study from http://blackgu.blogbus.com/logs/69596661.html
 *
 */
public class CountDownLatchTest {

	static boolean isOver = false;
	
	public static void main(String[] args) throws InterruptedException {
		
		//计时线程
		new Thread() {
			public void run() {
				SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				for (int i = 0; !isOver && i < 1000; i++) {
					System.out.println("\t\t\t\t\t\t"+format.format(new Date()));
					try {
						Thread.sleep(500);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}.start();
		
		Thread.sleep(1000);
		
		final CountDownLatch 各就位 = new CountDownLatch(5);
		final CountDownLatch 鸣枪 = new CountDownLatch(1);
		final CountDownLatch 跑 = new CountDownLatch(5);
		
		Thread[] threads = new Thread[5];//运动员线程
		for (int i = 0; i < threads.length; i++) {
			threads[i] = new Thread("运动员" + i) {
				public void run() {
					
					try {
						Thread.sleep(500+(long)(Math.random() * 2000));
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					
					System.out.println(this.getName() + "到位(等待发令...)");
					各就位.countDown();
					try {
						鸣枪.await();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					long begin = System.currentTimeMillis();
					System.out.println(this.getName() + "开始跑");
					try {
						Thread.sleep(3000+(long)(Math.random() * 3000));
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					
					long end = System.currentTimeMillis();
					System.out.println(this.getName() + "到终点(耗时:" + (end-begin) +"ms).");
					跑.countDown();
				}
			};
			threads[i].start();
		}
		
		System.out.println("【发令员】各就位---(等等运动员到位...)");
		各就位.await();//发令员等待运动员到位
		
		Thread.sleep(2000);
		
		System.out.println("【发令员】预备---(准备鸣枪)");
		Thread.sleep(1000);
		
		System.out.println("【发令员】鸣枪!---(等等运动员到终点...)");
		
		鸣枪.countDown();//所运动员到位, 鸣枪示意可以跑
		
//		System.out.println("【解说员】运动员跑起来...");

		跑.await();//等等运动员到终点
		
		System.out.println("---所有到终点!");
		isOver = true;
	}
}



=======system out==================
						2011-07-20 14:37:42
						2011-07-20 14:37:42
【发令员】各就位---(等等运动员到位...)
						2011-07-20 14:37:43
						2011-07-20 14:37:43
运动员1到位(等待发令...)
运动员2到位(等待发令...)
						2011-07-20 14:37:44
运动员0到位(等待发令...)
运动员3到位(等待发令...)
						2011-07-20 14:37:44
						2011-07-20 14:37:45
运动员4到位(等待发令...)
						2011-07-20 14:37:45
						2011-07-20 14:37:46
						2011-07-20 14:37:46
						2011-07-20 14:37:47
【发令员】预备---(准备鸣枪)
						2011-07-20 14:37:47
						2011-07-20 14:37:48
【发令员】鸣枪!---(等等运动员到终点...)
运动员1开始跑
运动员2开始跑
运动员0开始跑
运动员3开始跑
运动员4开始跑
						2011-07-20 14:37:48
						2011-07-20 14:37:49
						2011-07-20 14:37:49
						2011-07-20 14:37:50
						2011-07-20 14:37:50
						2011-07-20 14:37:51
						2011-07-20 14:37:51
运动员3到终点(耗时:3603ms).
运动员2到终点(耗时:3630ms).
运动员0到终点(耗时:3793ms).
						2011-07-20 14:37:52
						2011-07-20 14:37:52
运动员1到终点(耗时:4762ms).
						2011-07-20 14:37:53
						2011-07-20 14:37:53
						2011-07-20 14:37:54
运动员4到终点(耗时:5987ms).
---所有到终点!

Global site tag (gtag.js) - Google Analytics