隨筆 - 18, 文章 - 0, 評論 - 8, 引用 - 0

          導航

          <2009年4月>
          2930311234
          567891011
          12131415161718
          19202122232425
          262728293012
          3456789

          常用鏈接

          留言簿(2)

          隨筆分類(17)

          隨筆檔案(18)

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          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 丑男 閱讀(180) | 評論 (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 丑男 閱讀(316) | 評論 (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 丑男 閱讀(219) | 評論 (0)編輯 收藏

          添加用戶【備份】

          useradd -g 501 -s /sbin/nologin builder

          posted @ 2013-05-06 17:25 丑男 閱讀(131) | 評論 (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 丑男 閱讀(277) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 宁强县| 大丰市| 晋宁县| 长岭县| 岳普湖县| 大化| 松滋市| 邻水| 增城市| 台南市| 浑源县| 舞阳县| 博罗县| 罗田县| 临桂县| 乐陵市| 涪陵区| 揭西县| 诸城市| 罗田县| 邯郸市| 华亭县| 汝阳县| 南汇区| 南开区| 武鸣县| 苏尼特左旗| 青冈县| 佛坪县| 泰宁县| 子洲县| 庆云县| 丹寨县| 朝阳市| 吉木萨尔县| 新密市| 淮阳县| 福泉市| 当雄县| 疏勒县| 通州市|