随笔 - 18, 文章 - 0, 评论 - 8, 引用 - 0
数据加载中……

2009年4月29日

CyclicBarrier 简单举例

一句话解释:预备~~~开始

 1 import java.util.concurrent.BrokenBarrierException;
 2 import java.util.concurrent.CyclicBarrier;
 3 
 4 import org.slf4j.Logger;
 5 import org.slf4j.LoggerFactory;
 6 
 7 public class CyclicBarrierLearn {
 8     
 9     private Logger log = LoggerFactory.getLogger(CyclicBarrierLearn.class);
10     
11     private class Work extends Thread {
12         
13         private String name;
14         private CyclicBarrier cyclicBarrier;
15         
16         public Work(String name, CyclicBarrier cyclicBarrier) {
17             this.name = name;
18             this.cyclicBarrier = cyclicBarrier;
19         }
20         
21         @Override
22         public void run() {
23             try {
24                 log.debug("thread name: " + name + " waiting work");
25                 cyclicBarrier.await();
26                 log.debug("thread name: " + name + " working");
27             } catch (InterruptedException e) {
28                 e.printStackTrace();
29             } catch (BrokenBarrierException e) {
30                 e.printStackTrace();
31             }
32             
33         }
34     }
35     
36     public void cyclicBarrier() {
37         CyclicBarrier cyclicBarrier = new CyclicBarrier(50, new Runnable() {
38             
39             @Override
40             public void run() {
41                 log.debug("let's begin work");
42             }
43         });
44         
45         for (int i = 0; i < cyclicBarrier.getParties(); i++) {
46             Work work = new Work(String.valueOf(i), cyclicBarrier);
47             work.start();
48         }
49         
50     }
51 
52     public static void main(String[] args) {
53         CyclicBarrierLearn cyclicBarrierLearn = new CyclicBarrierLearn();
54         cyclicBarrierLearn.cyclicBarrier();
55 
56     }
57 
58 }
59 

posted @ 2017-07-13 11:39 丑男 阅读(158) | 评论 (0)编辑 收藏

CountDownLatch 简单举例

一句话解释:主线程阻塞,其他线程完成后,主线程被唤醒后继续执行

 1 import java.util.Random;
 2 import java.util.concurrent.CountDownLatch;
 3 
 4 import org.slf4j.Logger;
 5 import org.slf4j.LoggerFactory;
 6 
 7 public class CountDownLatchLearn {
 8     
 9     private Logger log = LoggerFactory.getLogger(CountDownLatchLearn.class);
10     private CountDownLatch countDownLatch;
11     
12     public CountDownLatchLearn() {
13         countDownLatch = new CountDownLatch(50);
14     }
15     
16     public void countDown() {
17         Long count = countDownLatch.getCount();
18         log.debug("countDownLatch count is:" + count.toString());
19         
20         for (int i = 0; i < count; i++) {
21             Work work = new Work(String.valueOf(i), countDownLatch);
22             work.start();
23         }
24         try {
25             countDownLatch.await();
26         } catch (InterruptedException e) {
27             e.printStackTrace();
28         }
29         log.debug("work finish!!!");
30     }
31     
32     private class Work extends Thread {
33         
34         private String name;
35         private CountDownLatch countDownLatch;
36         
37         public Work(String name, CountDownLatch countDownLatch) {
38             this.name = name;
39             this.countDownLatch = countDownLatch;
40         }
41         
42         @Override
43         public void run() {
44             Random r = new Random();
45             int sleep = r.nextInt(2000);
46             try {
47                 log.debug("thread sleep: "+ sleep);
48                 Thread.sleep(sleep);
49             } catch (InterruptedException e) {
50                 e.printStackTrace();
51             }
52             log.debug("thread: " + name + ": do work");
53             countDownLatch.countDown();
54         }
55     }
56 
57     public static void main(String[] args) {
58         System.out.println("main start!!!");
59         
60         CountDownLatchLearn countDownLatchLearn = new CountDownLatchLearn();
61         countDownLatchLearn.countDown();
62         
63         System.out.println("main end!!!");
64     }
65 
66 }

posted @ 2017-07-13 11:18 丑男 阅读(293) | 评论 (0)编辑 收藏

mysql 5.7 for windows安装过程

环境说明:

OSwindows 7 64bit Databasemysql-5.7.18-winx64 Noinstall版本

 

1. 解压Mysql安装目录

2. 编写my.ini配置文件

3. mysqld --defaults-file=../my.ini --initialize

4. ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';

5. mysql –u root –p

6. 密码在logs/*.err日志中

 
my.ini文件内容

 1 # my.ini文件内容
 2 # For advice on how to change settings please see
 3 # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
 4 # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
 5 # *** default location during install, and will be replaced if you
 6 # *** upgrade to a newer version of MySQL.
 7 
 8 [mysqld]
 9 
10 # Remove leading # and set to the amount of RAM for the most important data
11 # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
12 # innodb_buffer_pool_size = 128M
13 
14 # Remove leading # to turn on a very important data integrity option: logging
15 # changes to the binary log between backups.
16 # log_bin
17 
18 # These are commonly set, remove the # and set as required.
19 basedir=D:\\mysql-5.7.18-winx64
20 datadir=D:\\mysql-5.7.18-winx64\\data
21 # port = ..
22 # server_id = ..
23 
24 
25 # Remove leading # to set options mainly useful for reporting servers.
26 # The server defaults are faster for transactions and fast SELECTs.
27 # Adjust sizes as needed, experiment to find the optimal values.
28 # join_buffer_size = 128M
29 # sort_buffer_size = 2M
30 # read_rnd_buffer_size = 2M 
31 
32 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
33 
34 long_query_time=0.1
35 slow_query_log=on
36 slow_query_log_file=D:\\mysql-5.7.18-winx64\\logs\\mysqlslow.log
37 

posted @ 2017-07-10 00:53 丑男 阅读(173) | 评论 (0)编辑 收藏

添加用户【备份】

useradd -g 501 -s /sbin/nologin builder

posted @ 2013-05-06 17:25 丑男 阅读(108) | 评论 (0)编辑 收藏

[ZT]Java虚拟机JVM的调优参数选择

在任何一个的生产系统上线前,系统性能调优(Tuning)都是很重要的一步。通常,应用系统的软硬件的缺省值都是给开发平台(或小规模系统)设计的,用来跑生产系统几乎都无法发挥出软硬件的最佳性能。有时,系统调优前后的性能会差好几倍。另一方面,由于应用程序的开发人员通常都是针对功能作开发的,因此,开发硬件都是比生产环境要小的机器。例如,生产系统是一台8个CPU,64GB内存服务器,而开发服务器可能只有1个CPU和4GB内存。所以,在开发人员中常常不具备做性能方面测试的软硬件环境。另外,有的程序员甚至在开发时都没有考虑到多用户并发的环境,程序中存在单点瓶颈等问题。在做压力测试和调优时,往往就会发现这些关键点。

  由于应用系统是个软硬件的完整统一体,系统调优往往需要涉及硬件、网络操作系统、中间件,应用程序和数据库等方面。在调优的过程中,往往需要发现存在瓶颈的地方(也就是导致系统变慢的部分),分析原因,从而改进和确定较优的参数。

  我们在作JVM的调优前,通常先要了解运行的硬件平台,操作系统和中间件,然后针对这些情况配置相应的系统参数,在测试中不断完善参数。由于性能调优需要对系统非常了解,并且需要丰富的经验,因此不是一件容易的事情。这里介绍一些很好的参考资料,就是SPEC.org的网站。这是硬件厂商公布benchmark测试结果的地方,通常硬件厂商会把系统调到最优化才公布结果的,因此很有借鉴意义。常见和JVM有关的benchmark值主要有SPECjAppServer2004和SPECjbb2005。前者是J2EE应用服务器的性能指标,后者是服务器端Java虚拟机的性能指标。给大家介绍这个网站的目的是说大家可以参考硬件厂商给出的JVM配置,在根据自己应用环境的特点,较快的得出较好的参数。例如,这个网页给出了SUN公司T5120服务器+应用服务器9.1 +JDK1.5的SPECjAppServer2004值是8,439.36:

  http://www.spec.org/jAppServer2004/results/res2007q4/jAppServer2004-20071106-00092.html

  我们现在要关心的不是Benchmark的值(注:实际上,Sun公司的这个值是个很不错的结果),而是留意在这种环境下JVM的参数配置,可以找到一个栏目“Notes / Tuning Information”:

  JVM Options: -server -XX:+AggressiveHeap

-Xmx2560m -Xms2560m -Xmn1024m -Xss128k

-XX:PermSize=256m

-XX:+DisableExplicitGC

-XX:ParallelGCThreads=24

-XX:LargePageSizeInBytes=256m

-XX:+UseParallelOldGC

-XX:+AggressiveOpts

-DAllowManagedFieldsInDefaultFetchGroup=true

-DAllowMediatedWriteInDefaultFetchGroup=true

-XX:-UseBiasedLocking

-Dcom.sun.ejb.containers.readonly.relative.refresh.mode=true

-Dcom.sun.jts.dblogging.insertquery=insert into

txn_log_table_0 values (
? , ? , ? )

-Dcom.sun.jts.dblogging.deletequery=delete from

txn_log_table_0 where localtid
= ? and servername = ?

-Dcom.sun.jdo.spi.persistence.support.sqlstore.

MULTILEVEL_PREFETCH
=true

  那么上面那些参数是什么意思呢?上述段落中“-XX”的参数是SUN JVM的扩展选项,其中以下的这些都是和垃圾回收(GC)有关:

  -XX:PermSize=256m

-XX:+DisableExplicitGC

-XX:ParallelGCThreads=24

-XX:+UseParallelOldGC

-XX:+AggressiveHeap

  下面这个选项是选择大的内存页面:

  -XX:LargePageSizeInBytes=256m

  "-XX:+AggressiveOpts"是一些试验性优化参数,“-XX:-UseBiasedLocking”是非竞争性的同步选项。

  而选项“-Xmx2560m -Xms2560m -Xmn1024m -Xss128k”则是初始堆栈的内存值,注意-Xmx和-Xms的值是一样的,这样系统性能会较平稳些。

  至于这些参数详细代表什么意义,大家可以google一下就很容易了解。这是Sun网站上的说明,有兴趣的可以读一下: http://java.sun.com/performance/reference/whitepapers/tuning.html

  如果你的应用系统是JDK1.5,硬件是T5120,操作系统是Solaris,那么这些参数就很有借鉴意义。如果你的硬件系统不是T5120,但是使用SUN的JDK1.5 ,这些参数也是有一定参考作用。当然,最理想的是选择一个和自己的环境最近似的结果来参考。大多数软硬件的测试结果都可以在SPEC.org上找到,如果你的系统是J2EE的3层架构,可以用jAppServer2004指标,如果是纯JAVA的应用,可用jbb2005的结果:

  http://www.spec.org/jAppServer2004/

  http://www.spec.org/jbb2005/

  需要注意的是,这些调优参数只是提供了一个思路,具体是否合适你的应用还要看实测结果。

posted @ 2009-04-29 19:24 丑男 阅读(248) | 评论 (0)编辑 收藏