-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
974 lines (612 loc) · 74.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>M的博客</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="description">
<meta property="og:type" content="website">
<meta property="og:title" content="M的博客">
<meta property="og:url" content="http://www.zhouming.org/index.html">
<meta property="og:site_name" content="M的博客">
<meta property="og:description">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="M的博客">
<meta name="twitter:description">
<link rel="alternative" href="/atom.xml" title="M的博客" type="application/atom+xml">
<link rel="icon" href="/img/favicon.png">
<link rel="stylesheet" href="//cdn.bootcss.com/animate.css/3.5.0/animate.min.css" type="text/css">
<link rel="stylesheet" href="/css/style.css" type="text/css">
<link rel="stylesheet" href="/font-awesome/css/font-awesome.min.css">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
<!-- 加载特效 -->
<script src="/js/pace.js"></script>
<link href="/css/pace/pace-theme-flash.css" rel="stylesheet" />
<script>
var yiliaConfig = {
rootUrl: '/',
fancybox: true,
animate: true,
isHome: true,
isPost: false,
isArchive: false,
isTag: false,
isCategory: false,
open_in_new: false
}
</script>
</head>
<body>
<div id="container">
<div class="left-col">
<div class="overlay"></div>
<div class="intrude-less">
<header id="header" class="inner">
<a href="/" class="profilepic">
<img lazy-src="/img/head.jpg" class="js-avatar">
</a>
<hgroup>
<h1 class="header-author"><a href="/" title="Hi Mate">M</a></h1>
</hgroup>
<p class="header-subtitle">道法自然</p>
<div id="switch-btn" class="switch-btn">
<div class="icon">
<div class="icon-ctn">
<div class="icon-wrap icon-house" data-idx="0">
<div class="birdhouse"></div>
<div class="birdhouse_holes"></div>
</div>
<div class="icon-wrap icon-ribbon hide" data-idx="1">
<div class="ribbon"></div>
</div>
<div class="icon-wrap icon-link hide" data-idx="2">
<div class="loopback_l"></div>
<div class="loopback_r"></div>
</div>
<div class="icon-wrap icon-me hide" data-idx="3">
<div class="user"></div>
<div class="shoulder"></div>
</div>
</div>
</div>
<div class="tips-box hide">
<div class="tips-arrow"></div>
<ul class="tips-inner">
<li>菜单</li>
<li>标签</li>
<li>友情链接</li>
<li>关于我</li>
</ul>
</div>
</div>
<div id="switch-area" class="switch-area">
<div class="switch-wrap">
<section class="switch-part switch-part1">
<nav class="header-menu">
<ul>
<li><a href="/tags">静心阅读</a></li>
</ul>
</nav>
<nav class="header-nav">
<ul class="social">
<a class="fl mail" target="_blank" href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=pp6fkZCXkpOU5tfXiMXJyw" title="mail">mail</a>
<a class="fl github" target="_blank" href="https://github.com/maynezhou" title="github">github</a>
</ul>
</nav>
</section>
<section class="switch-part switch-part2">
<div class="widget tagcloud" id="js-tagcloud">
<a href="/tags/FixedUpdate/" style="font-size: 10px;">FixedUpdate</a> <a href="/tags/GitHub/" style="font-size: 10px;">GitHub</a> <a href="/tags/Hexo/" style="font-size: 10px;">Hexo</a> <a href="/tags/Idea/" style="font-size: 10px;">Idea</a> <a href="/tags/Netty/" style="font-size: 10px;">Netty</a> <a href="/tags/NexT/" style="font-size: 10px;">NexT</a> <a href="/tags/Spring/" style="font-size: 15px;">Spring</a> <a href="/tags/Tomcat/" style="font-size: 10px;">Tomcat</a> <a href="/tags/Update/" style="font-size: 10px;">Update</a> <a href="/tags/junit/" style="font-size: 10px;">junit</a> <a href="/tags/log4j/" style="font-size: 10px;">log4j</a> <a href="/tags/技术/" style="font-size: 10px;">技术</a> <a href="/tags/生活/" style="font-size: 20px;">生活</a> <a href="/tags/诗/" style="font-size: 10px;">诗</a>
</div>
</section>
<section class="switch-part switch-part3">
<div id="js-friends">
<a target="_blank" class="main-nav-link switch-friends-link" href="http://user.qzone.qq.com/369454080?ADUIN=89761452&ADSESSION=1481685899&ADTAG=CLIENT.QQ.5503_FriendInfo_PersonalInfo.0&ADPUBNO=26642&ptlang=2052">lp</a>
</div>
</section>
<section class="switch-part switch-part4">
<div id="js-aboutme">人法地、地法天、天法道、道法自然</div>
</section>
</div>
</div>
</header>
</div>
</div>
<div class="mid-col">
<nav id="mobile-nav">
<div class="overlay">
<div class="slider-trigger"></div>
<h1 class="header-author js-mobile-header hide"><a href="/" title="Me">M</a></h1>
</div>
<div class="intrude-less">
<header id="header" class="inner">
<a href="/" class="profilepic">
<img lazy-src="/img/head.jpg" class="js-avatar">
</a>
<hgroup>
<h1 class="header-author"><a href="/" title="Me">M</a></h1>
</hgroup>
<p class="header-subtitle">道法自然</p>
<nav class="header-menu">
<ul>
<li><a href="/tags">静心阅读</a></li>
<div class="clearfix"></div>
</ul>
</nav>
<nav class="header-nav">
<div class="social">
<a class="mail" target="_blank" href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=pp6fkZCXkpOU5tfXiMXJyw" title="mail">mail</a>
<a class="github" target="_blank" href="https://github.com/maynezhou" title="github">github</a>
</div>
</nav>
</header>
</div>
</nav>
<div class="body-wrap">
<article id="post-junit" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2016/12/15/junit/" class="article-date">
<time datetime="2016-12-15T08:06:00.000Z" itemprop="datePublished">2016-12-15</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2016/12/15/junit/">Junit</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<h1 id="Junit">Junit</h1><p>偶然使用下 junit 还比较方便,主要可以快速运行测试方法。<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.HashMap;</span><br><span class="line"><span class="keyword">import</span> java.util.Map;</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Test</span> </span>{</span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span></span>{</span><br><span class="line"> <span class="keyword">int</span> a = <span class="number">0x10000001</span>;</span><br><span class="line"> HashMap<Integer,Integer> b = <span class="keyword">new</span> HashMap<Integer, Integer>();</span><br><span class="line"> b.put(a,<span class="number">999</span>);</span><br><span class="line"> <span class="keyword">for</span>(Map.Entry<Integer,Integer> entry : b.entrySet()){</span><br><span class="line"> <span class="keyword">int</span> k = entry.getKey();</span><br><span class="line"> <span class="keyword">int</span> v = entry.getValue();</span><br><span class="line"> System.out.println(k+<span class="string">","</span>+v);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="annotation">@org</span>.junit.Test <span class="comment">//在idea编辑器上左边会有个绿色小箭头,按下就可以运行了!不用main了</span></span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">test1</span><span class="params">()</span></span>{</span><br><span class="line"> System.out.println(<span class="string">"test111111"</span>);</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure></p>
</div>
<div class="article-info article-info-index">
<div class="article-category tagcloud">
<a class="article-category-link" href="/categories/Java服务器/">Java服务器</a>
</div>
<div class="article-tag tagcloud">
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/junit/">junit</a></li></ul>
</div>
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-刀" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2016/12/10/刀/" class="article-date">
<time datetime="2016-12-10T01:30:00.000Z" itemprop="datePublished">2016-12-10</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2016/12/10/刀/">刀</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<h1 id="刀">刀</h1><p>刀,兵也。-《说文解字》<br>夫兵,犹火也。-《左转》</p>
<p>夫妻间动刀,那才叫玩火自焚,咎由自取!</p>
<p>共勉之!</p>
</div>
<div class="article-info article-info-index">
<div class="article-category tagcloud">
<a class="article-category-link" href="/categories/生活/">生活</a>
</div>
<div class="article-tag tagcloud">
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/生活/">生活</a></li></ul>
</div>
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-log4j" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2016/11/11/log4j/" class="article-date">
<time datetime="2016-11-11T06:52:00.000Z" itemprop="datePublished">2016-11-11</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2016/11/11/log4j/">log4j</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br></pre></td><td class="code"><pre><span class="line"><span class="pi"><?xml version="1.0" encoding="UTF-8" ?></span></span><br><span class="line"><span class="doctype"><!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"></span></span><br><span class="line"><span class="tag"><<span class="title">log4j:configuration</span> <span class="attribute">xmlns:log4j</span>=<span class="value">"http://jakarta.apache.org/log4j/"</span>></span></span><br><span class="line"> <span class="comment"><!-- 输出日志到控制台 ConsoleAppender --></span></span><br><span class="line"> <span class="tag"><<span class="title">appender</span> <span class="attribute">name</span>=<span class="value">"console"</span></span><br><span class="line"> <span class="attribute">class</span>=<span class="value">"org.apache.log4j.ConsoleAppender"</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">param</span> <span class="attribute">name</span>=<span class="value">"Threshold"</span> <span class="attribute">value</span>=<span class="value">"debug"</span>></span><span class="tag"></<span class="title">param</span>></span></span><br><span class="line"> <span class="comment"><!--<param name="Target" value="System.err"></param>--></span> <span class="comment"><!-- 红色打印 --></span></span><br><span class="line"> <span class="comment"><!--<param name="Target" value="System.out"></param> &lt;!&ndash; 黑色打印 &ndash;&gt;--></span></span><br><span class="line"> <span class="tag"><<span class="title">layout</span> <span class="attribute">class</span>=<span class="value">"org.apache.log4j.PatternLayout"</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">param</span> <span class="attribute">name</span>=<span class="value">"ConversionPattern"</span> <span class="attribute">value</span>=<span class="value">"[%d{yyyy-MM-dd HH:mm:ss\} %-5p] [%t] {%c:%L}:%m%n"</span>></span><span class="tag"></<span class="title">param</span>></span></span><br><span class="line"> <span class="tag"></<span class="title">layout</span>></span></span><br><span class="line"> <span class="tag"></<span class="title">appender</span>></span></span><br><span class="line"></span><br><span class="line"> <span class="comment"><!--日志架构需求--></span></span><br><span class="line"> <span class="comment"><!-- 【后台日志】实时写入的日志文件,包含服务器全部日志信息,作为观察后台使用,每次启服可以覆盖 --></span></span><br><span class="line"> <span class="comment"><!-- 【主日志】服务器主日志文件,包含服务器全部日志信息,作为永久数据进行存储,每天一个文件 --></span></span><br><span class="line"> <span class="comment"><!-- 【异常日志】服务器错误日志文件,包含服务器代码运行异常的日志信息,作为永久数据进行存储,每天一个文件 --></span></span><br><span class="line"> <span class="comment"><!-- 【预警日志】服务器预警,当服务器发生严重异常的时候,向某些邮箱发送邮件以通知相关人员--></span></span><br><span class="line"> <span class="comment"><!-- 【功能日志】服务器功能模块日志文件,按照日志统计需求存储相应的数据日志,作为永久数据进行存储,每天一批文件,按照功能划分文件 --></span></span><br><span class="line"></span><br><span class="line"> <span class="comment"><!-- 后台日志 --></span></span><br><span class="line"> <span class="tag"><<span class="title">appender</span> <span class="attribute">name</span>=<span class="value">"_console"</span></span><br><span class="line"> <span class="attribute">class</span>=<span class="value">"org.apache.log4j.FileAppender"</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">param</span> <span class="attribute">name</span>=<span class="value">"File"</span> <span class="attribute">value</span>=<span class="value">"logs/_console.log"</span>></span><span class="tag"></<span class="title">param</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">param</span> <span class="attribute">name</span>=<span class="value">"ImmediateFlush"</span> <span class="attribute">value</span>=<span class="value">"true"</span>></span><span class="tag"></<span class="title">param</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">param</span> <span class="attribute">name</span>=<span class="value">"Threshold"</span> <span class="attribute">value</span>=<span class="value">"debug"</span>></span><span class="tag"></<span class="title">param</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">param</span> <span class="attribute">name</span>=<span class="value">"Append"</span> <span class="attribute">value</span>=<span class="value">"false"</span>></span><span class="tag"></<span class="title">param</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">layout</span> <span class="attribute">class</span>=<span class="value">"org.apache.log4j.PatternLayout"</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">param</span> <span class="attribute">name</span>=<span class="value">"ConversionPattern"</span> <span class="attribute">value</span>=<span class="value">"[%d{yyyy-MM-dd HH:mm:ss\} %-5p] [%t] {%c:%L}:%m%n"</span>></span><span class="tag"></<span class="title">param</span>></span></span><br><span class="line"> <span class="tag"></<span class="title">layout</span>></span></span><br><span class="line"> <span class="tag"></<span class="title">appender</span>></span></span><br><span class="line"> <span class="comment"><!-- 主日志 --></span></span><br><span class="line"> <span class="tag"><<span class="title">appender</span> <span class="attribute">name</span>=<span class="value">"server"</span></span><br><span class="line"> <span class="attribute">class</span>=<span class="value">"org.apache.log4j.DailyRollingFileAppender"</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">param</span> <span class="attribute">name</span>=<span class="value">"Threshold"</span> <span class="attribute">value</span>=<span class="value">"info"</span>></span><span class="tag"></<span class="title">param</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">param</span> <span class="attribute">name</span>=<span class="value">"ImmediateFlush"</span> <span class="attribute">value</span>=<span class="value">"true"</span>></span><span class="tag"></<span class="title">param</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">param</span> <span class="attribute">name</span>=<span class="value">"File"</span> <span class="attribute">value</span>=<span class="value">"logs/server.log"</span>></span><span class="tag"></<span class="title">param</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">param</span> <span class="attribute">name</span>=<span class="value">"DatePattern"</span> <span class="attribute">value</span>=<span class="value">"'.'yyyy-MM-dd'.log'"</span>></span><span class="tag"></<span class="title">param</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">layout</span> <span class="attribute">class</span>=<span class="value">"org.apache.log4j.PatternLayout"</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">param</span> <span class="attribute">name</span>=<span class="value">"ConversionPattern"</span> <span class="attribute">value</span>=<span class="value">"[%d{yyyy-MM-dd HH:mm:ss\} %-5p] [%t] {%c:%L}:%m%n"</span>></span><span class="tag"></<span class="title">param</span>></span></span><br><span class="line"> <span class="tag"></<span class="title">layout</span>></span></span><br><span class="line"> <span class="tag"></<span class="title">appender</span>></span></span><br><span class="line"></span><br><span class="line"> <span class="comment"><!-- 异常日志 --></span></span><br><span class="line"> <span class="tag"><<span class="title">appender</span> <span class="attribute">name</span>=<span class="value">"error"</span></span><br><span class="line"> <span class="attribute">class</span>=<span class="value">"org.apache.log4j.DailyRollingFileAppender"</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">param</span> <span class="attribute">name</span>=<span class="value">"Threshold"</span> <span class="attribute">value</span>=<span class="value">"warn"</span>></span><span class="tag"></<span class="title">param</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">param</span> <span class="attribute">name</span>=<span class="value">"ImmediateFlush"</span> <span class="attribute">value</span>=<span class="value">"true"</span>></span><span class="tag"></<span class="title">param</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">param</span> <span class="attribute">name</span>=<span class="value">"Target"</span> <span class="attribute">value</span>=<span class="value">"System.err"</span>></span><span class="tag"></<span class="title">param</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">param</span> <span class="attribute">name</span>=<span class="value">"File"</span> <span class="attribute">value</span>=<span class="value">"logs/error.log"</span>></span><span class="tag"></<span class="title">param</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">param</span> <span class="attribute">name</span>=<span class="value">"DatePattern"</span> <span class="attribute">value</span>=<span class="value">"'.'yyyy-MM-dd'.log'"</span>></span><span class="tag"></<span class="title">param</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">layout</span> <span class="attribute">class</span>=<span class="value">"org.apache.log4j.PatternLayout"</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">param</span> <span class="attribute">name</span>=<span class="value">"ConversionPattern"</span> <span class="attribute">value</span>=<span class="value">"[%d{yyyy-MM-dd HH:mm:ss\} %-5p] [%t] {%c:%L}:%m%n"</span>></span><span class="tag"></<span class="title">param</span>></span></span><br><span class="line"> <span class="tag"></<span class="title">layout</span>></span></span><br><span class="line"> <span class="tag"></<span class="title">appender</span>></span></span><br><span class="line"></span><br><span class="line"> <span class="comment"><!-- 预警日志 --></span></span><br><span class="line"> <span class="comment"><!--TODO--></span></span><br><span class="line"> <span class="comment"><!-- 功能日志 --></span></span><br><span class="line"> <span class="comment"><!--TODO--></span></span><br><span class="line"></span><br><span class="line"> <span class="tag"><<span class="title">root</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">priority</span> <span class="attribute">value</span>=<span class="value">"debug"</span> /></span></span><br><span class="line"> <span class="tag"><<span class="title">appender-ref</span> <span class="attribute">ref</span>=<span class="value">"console"</span> /></span></span><br><span class="line"> <span class="tag"><<span class="title">appender-ref</span> <span class="attribute">ref</span>=<span class="value">"_console"</span> /></span></span><br><span class="line"> <span class="tag"><<span class="title">appender-ref</span> <span class="attribute">ref</span>=<span class="value">"server"</span> /></span></span><br><span class="line"></span><br><span class="line"> <span class="tag"></<span class="title">root</span>></span></span><br><span class="line"></span><br><span class="line"><span class="tag"></<span class="title">log4j:configuration</span>></span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"><!--log4j.xml配置文件参数说明--></span></span><br><span class="line"><span class="comment"><!-- https://wiki.apache.org/logging-log4j/Log4jXmlFormat --></span></span><br><span class="line"><span class="comment"><!--</span><br><span class="line">===================================================</span><br><span class="line">输出级别的种类</span><br><span class="line"> OFF 、FATAL 、ERROR、WARN、INFO、DEBUG、TRACE 、ALL</span><br><span class="line"> OFF 为最高等级 关闭了日志信息</span><br><span class="line"> FATAL 为可能导致应用中止的严重事件错误</span><br><span class="line"> ERROR 为严重错误 主要是程序的错误</span><br><span class="line"> WARN 为一般警告,比如session丢失</span><br><span class="line"> INFO 为一般要显示的信息,比如登录登出</span><br><span class="line"> DEBUG 为程序的调试信息</span><br><span class="line"> TRACE 为比DEBUG更细粒度的事件信息</span><br><span class="line"> ALL 为最低等级,将打开所有级别的日志</span><br><span class="line">===================================================</span><br><span class="line">配置日志信息输出目的地</span><br><span class="line"> org.apache.log4j.ConsoleAppender【控制台】</span><br><span class="line"> log4j.appender.console.Threshold=DEBUG 指定日志消息的输出最低层次。</span><br><span class="line"> log4j.appender.console.ImmediateFlush=true 默认值是true,意谓着所有的消息都会被立即输出。</span><br><span class="line"> log4j.appender.console.Target=System.err 默认情况下是:System.out,指定输出控制台</span><br><span class="line"> org.apache.log4j.FileAppender【文件】</span><br><span class="line"> log4j.appender.logFile.Threshold=DEBUG 指定日志消息的输出最低层次。</span><br><span class="line"> log4j.appender.logFile.ImmediateFlush=true 默认值是true,意谓着所有的消息都会被立即输出。</span><br><span class="line"> log4j.appender.logFile.Append=false 默认值是true,即将消息增加到指定文件中,false指将消息覆盖指定的文件内容。</span><br><span class="line"> log4j.appender.logFile.File=D:/logs/log.log4j 指定消息输出到log.log4j文件。</span><br><span class="line"> org.apache.log4j.DailyRollingFileAppender【每天产生一个日志文件】</span><br><span class="line"> log4j.appender.dailyFile.Threshold=DEBUG 指定日志消息的输出最低层次。</span><br><span class="line"> log4j.appender.dailyFile.ImmediateFlush=true 默认值是true,意谓着所有的消息都会被立即输出。</span><br><span class="line"> log4j.appender.dailyFile.Append=true 默认值是true,即将消息增加到指定文件中,false指将消息覆盖指定的文件内容。</span><br><span class="line"> log4j.appender.dailyFile.File=D:/logs/log.log4j 指定消息输出到log.log4j文件。</span><br><span class="line"> log4j.appender.dailyFile.DatePattern='.'yyyy-MM-dd 文件命名规范</span><br><span class="line"> org.apache.log4j.RollingFileAppender【文件大小到达指定尺寸的时候产生一个新的文件】</span><br><span class="line"> log4j.appender.rollingFile.Threshold=DEBUG 指定日志消息的输出最低层次。</span><br><span class="line"> log4j.appender.rollingFile.ImmediateFlush=true 默认值是true,意谓着所有的消息都会被立即输出。</span><br><span class="line"> log4j.appender.rollingFile.Append=true 默认值是true,即将消息增加到指定文件中,false指将消息覆盖指定的文件内容。</span><br><span class="line"> log4j.appender.rollingFile.File=D:/logs/log.log4j 指定消息输出到log.log4j文件。</span><br><span class="line"> log4j.appender.rollingFile.MaxFileSize=200KB 后缀可以是KB, MB 或者是 GB. 在日志文件到达该大小时,将会自动滚动,即将原来的内容移到log.log4j.1文件。</span><br><span class="line"> log4j.appender.rollingFile.MaxBackupIndex=2 指定可以产生的滚动文件的最大数。</span><br><span class="line"> log4j.appender.rollingFile.layout=org.apache.log4j.PatternLayout</span><br><span class="line"> log4j.appender.A1.layout.ConversionPattern=%-4r %-5p %d{yyyy-MM-dd HH:mm:ssS} %c %m%n</span><br><span class="line"> org.apache.log4j.WriterAppender【将日志信息以流格式发送到任意指定的地方】</span><br><span class="line"> org.apache.log4j.net.SMTPAppender【发送日志到指定邮件】</span><br><span class="line"> log4j.appender.mail=org.apache.log4j.net.SMTPAppender</span><br><span class="line"> log4j.appender.mail.Threshold=FATAL</span><br><span class="line"> log4j.appender.mail.BufferSize=10</span><br><span class="line"> log4j.appender.mail.From = [email protected]</span><br><span class="line"> log4j.appender.mail.SMTPHost=mail.com</span><br><span class="line"> log4j.appender.mail.Subject=Log4J Message</span><br><span class="line"> log4j.appender.mail.To= [email protected]</span><br><span class="line"> org.apache.log4j.jdbc.JDBCAppender【应用于数据库】</span><br><span class="line">===================================================</span><br><span class="line">配置日志信息的格式</span><br><span class="line"> org.apache.log4j.HTMLLayout(以HTML表格形式布局),</span><br><span class="line"> org.apache.log4j.PatternLayout(可以灵活地指定布局模式),</span><br><span class="line"> org.apache.log4j.SimpleLayout(包含日志信息的级别和信息字符串),</span><br><span class="line"> org.apache.log4j.TTCCLayout(包含日志产生的时间、线程、类别等等信息)</span><br><span class="line">===================================================</span><br><span class="line">日志信息格式中几个符号所代表的含义:</span><br><span class="line"> -X号: X信息输出时左对齐;</span><br><span class="line"> %p: 输出日志信息优先级,即DEBUG,INFO,WARN,ERROR,FATAL,</span><br><span class="line"> %d: 输出日志时间点的日期或时间,默认格式为ISO8601,也可以在其后指定格式,比如:%d{yyy MMM dd HH:mm:ss,SSS},输出类似:2002年10月18日 22:10:28,921</span><br><span class="line"> %r: 输出自应用启动到输出该log信息耗费的毫秒数</span><br><span class="line"> %c: 输出日志信息所属的类目,通常就是所在类的全名</span><br><span class="line"> %t: 输出产生该日志事件的线程名</span><br><span class="line"> %l: 输出日志事件的发生位置,相当于%C.%M(%F:%L)的组合,包括类目名、发生的线程,以及在代码中的行数。举例:Testlog4.main (TestLog4.java:10)</span><br><span class="line"> %x: 输出和当前线程相关联的NDC(嵌套诊断环境),尤其用到像java servlets这样的多客户多线程的应用中。</span><br><span class="line"> %%: 输出一个"%"字符</span><br><span class="line"> %F: 输出日志消息产生时所在的文件名称</span><br><span class="line"> %L: 输出代码中的行号</span><br><span class="line"> %m: 输出代码中指定的消息,产生的日志具体信息</span><br><span class="line"> %n: 输出一个回车换行符,Windows平台为"/r/n",Unix平台为"/n"输出日志信息换行</span><br><span class="line"> 可以在%与模式字符之间加上修饰符来控制其最小宽度、最大宽度、和文本的对齐方式。如:</span><br><span class="line"> 1)%20c:指定输出category的名称,最小的宽度是20,如果category的名称小于20的话,默认的情况下右对齐。</span><br><span class="line"> 2)%-20c:指定输出category的名称,最小的宽度是20,如果category的名称小于20的话,"-"号指定左对齐。</span><br><span class="line"> 3)%.30c:指定输出category的名称,最大的宽度是30,如果category的名称大于30的话,就会将左边多出的字符截掉,但小于30的话也不会有空格。</span><br><span class="line"> 4)%20.30c:如果category的名称小于20就补空格,并且右对齐,如果其名称长于30字符,就从左边较远输出的字符截掉。</span><br><span class="line">===================================================</span><br><span class="line"></span><br><span class="line">--></span></span><br></pre></td></tr></table></figure>
</div>
<div class="article-info article-info-index">
<div class="article-category tagcloud">
<a class="article-category-link" href="/categories/Java服务器/">Java服务器</a>
</div>
<div class="article-tag tagcloud">
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/log4j/">log4j</a></li></ul>
</div>
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-Idea-自定义-LiveTemplates" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2016/11/11/Idea-自定义-LiveTemplates/" class="article-date">
<time datetime="2016-11-11T06:25:00.000Z" itemprop="datePublished">2016-11-11</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2016/11/11/Idea-自定义-LiveTemplates/">Idea 自定义 LiveTemplates</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<h1 id="Idea_自定义_LiveTemplates">Idea 自定义 LiveTemplates</h1><p>设置自定义LiveTemplates,方便使用。<br><em>注:idea的设置已经导出为 setting.jar了,之后可以直接导入。<br>另外关于方法的注释应该在方法作用域内才能起作用,就是在方法中注释下再剪切到方法头。。。</em><br>创建Template Group: zm_custom<br>组下创建以下快捷键方式: </p>
<ol>
<li>类注释<br>Abbreviation: z_classdes<br>Description: addClassDes<br>```java<br>/**</li>
</ol>
<ul>
<li>$cursor$</li>
<li></li>
<li>@author Zhou Ming</li>
<li>@see $package$.$class$ </li>
<li>@since 0.9<br>*/<br>``` </li>
</ul>
<table>
<thead>
<tr>
<th>Name</th>
<th>Expression </th>
</tr>
</thead>
<tbody>
<tr>
<td>cursor</td>
<td></td>
</tr>
<tr>
<td>package</td>
<td>currentPackage()</td>
</tr>
<tr>
<td>class</td>
<td>className() </td>
</tr>
</tbody>
</table>
<ol>
<li>方法注释<br>Abbreviation: z_methoddes<br>Description: addMethod Des<pre><code class="java"><span class="comment">/**
* $cursor$
*
$params$
* <span class="doctag">@return</span> $return$
* <span class="doctag">@throws</span>
*/</span>
</code></pre>
Name | Expression<br>—|—<br>cursor |<br>params | ==@注释==<br>return | methodReturnType() </li>
</ol>
<p><em>==注释==:groovyScript(“def result=’’; def params=\”${_1}\”.replaceAll(‘[\\[|\\]|\\s]’, ‘’).split(‘,’).toList(); for(i = 0; i < params.size(); i++) {result+=’ </em> @param ‘ + params[i] + ((i < params.size() - 1) ? ‘\n’ : ‘’)}; return result”, methodParameters())*</p>
<ol>
<li>switch<br>Abbreviation: z_swit<br>Description: switch case<pre><code class="java"><span class="keyword">switch</span>($VAR$){
<span class="keyword">case</span> $VAR_CHILDREN$:
<span class="keyword">break</span>;$END$
}
</code></pre>
Name | Expression<br>—|—<br>VAR | suggestVariableName()<br>VAR_CHILDREN | suggestVariableName()</li>
<li>控制台打印<br>Abbreviation: z_sysout<br>Description: System.out.println<pre><code class="java">System.out.println($cursor$);
</code></pre>
Name | Expression<br>—|—<br>cursor | </li>
<li>日志注册<br>Abbreviation: z_log<br>Description: create log<pre><code class="java"><span class="keyword">private</span> Logger logger = LoggerFactory.getLogger($<span class="class"><span class="keyword">class</span>$.<span class="title">class</span>)</span>;
</code></pre>
Name | Expression<br>—|—<br>class | className()</li>
</ol>
</div>
<div class="article-info article-info-index">
<div class="article-category tagcloud">
<a class="article-category-link" href="/categories/IDE/">IDE</a>
</div>
<div class="article-tag tagcloud">
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Idea/">Idea</a></li></ul>
</div>
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-slf4j-是什么" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2016/11/09/slf4j-是什么/" class="article-date">
<time datetime="2016-11-09T06:42:00.000Z" itemprop="datePublished">2016-11-09</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2016/11/09/slf4j-是什么/">slf4j 是什么</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<h1 id="slf4j_相关概念">slf4j 相关概念</h1><p>slf4j 是一种日志框架,按此框架搭建日志系统之后可以随意切换具体日志系统,比如使用log4j或是java原生日志。</p>
</div>
<div class="article-info article-info-index">
<div class="article-category tagcloud">
<a class="article-category-link" href="/categories/Java服务器/">Java服务器</a>
</div>
<div class="article-tag tagcloud">
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Spring/">Spring</a></li></ul>
</div>
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-Spring是什么" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2016/11/09/Spring是什么/" class="article-date">
<time datetime="2016-11-09T03:48:00.000Z" itemprop="datePublished">2016-11-09</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2016/11/09/Spring是什么/">Spring是什么</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<h1 id="Spring相关概念">Spring相关概念</h1><p>Spring 是容器管理,主要管理bean 和 properties文件。通过ApplicationContext.xml进行管理</p>
<p>关于路径:<br>classpath:引用src目录下的文件写法<br>file:绝对路径写法</p>
</div>
<div class="article-info article-info-index">
<div class="article-category tagcloud">
<a class="article-category-link" href="/categories/Java服务器/">Java服务器</a>
</div>
<div class="article-tag tagcloud">
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Spring/">Spring</a></li></ul>
</div>
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-Spring-applicationcontext-xml-模版" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2016/11/08/Spring-applicationcontext-xml-模版/" class="article-date">
<time datetime="2016-11-08T02:00:24.000Z" itemprop="datePublished">2016-11-08</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2016/11/08/Spring-applicationcontext-xml-模版/">Tomcat诡异的自动关闭</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="pi"><?xml version="1.0" encoding="UTF-8"?></span></span><br><span class="line"><span class="tag"><<span class="title">beans</span> <span class="attribute">xmlns</span>=<span class="value">"http://www.springframework.org/schema/beans"</span></span><br><span class="line"> <span class="attribute">xmlns:xsi</span>=<span class="value">"http://www.w3.org/2001/XMLSchema-instance"</span> <span class="attribute">xmlns:util</span>=<span class="value">"http://www.springframework.org/schema/util"</span></span><br><span class="line"> <span class="attribute">xsi:schemaLocation</span>=<span class="value">"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"</span>></span></span><br><span class="line"></span><br><span class="line"> <span class="tag"><<span class="title">bean</span> <span class="attribute">id</span>=<span class="value">"propertyConfigurer"</span></span><br><span class="line"> <span class="attribute">class</span>=<span class="value">"com.yushang.config.serverPropertyPlaceholderConfigurer"</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">property</span> <span class="attribute">name</span>=<span class="value">"locations"</span>></span></span><br><span class="line"> <span class="comment"><!--list读取一系列配置文件--></span></span><br><span class="line"> <span class="tag"><<span class="title">list</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">value</span>></span></span><br><span class="line"> deploy/res/properties/server.properties</span><br><span class="line"> <span class="tag"></<span class="title">value</span>></span></span><br><span class="line"> <span class="tag"></<span class="title">list</span>></span></span><br><span class="line"> <span class="tag"></<span class="title">property</span>></span></span><br><span class="line"></span><br><span class="line"> <span class="tag"><<span class="title">property</span> <span class="attribute">name</span>=<span class="value">"fileEncoding"</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">value</span>></span>UTF-8<span class="tag"></<span class="title">value</span>></span></span><br><span class="line"> <span class="tag"></<span class="title">property</span>></span></span><br><span class="line"> <span class="tag"></<span class="title">bean</span>></span></span><br><span class="line"> <span class="comment"><!--&lt;!&ndash;服务器信息&ndash;&gt;--></span></span><br><span class="line"> <span class="comment"><!--<bean id="serverInfo" class="com.yushang.server.ServerInfo">--></span></span><br><span class="line"> <span class="comment"><!--<property name="port" value="${server.port}" />--></span></span><br><span class="line"> <span class="comment"><!--</bean>--></span></span><br><span class="line"></span><br><span class="line"> <span class="comment"><!--服务器初始化器--></span></span><br><span class="line"> <span class="tag"><<span class="title">bean</span> <span class="attribute">id</span>=<span class="value">"serverInit"</span> <span class="attribute">class</span>=<span class="value">"com.yushang.server.ServerInit"</span></span><br><span class="line"> <span class="attribute">init-method</span>=<span class="value">"init"</span>></span></span><br><span class="line"> <span class="tag"></<span class="title">bean</span>></span></span><br><span class="line"><span class="tag"></<span class="title">beans</span>></span></span><br></pre></td></tr></table></figure>
</div>
<div class="article-info article-info-index">
<div class="article-category tagcloud">
<a class="article-category-link" href="/categories/Java服务器/">Java服务器</a>
</div>
<div class="article-tag tagcloud">
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Spring/">Spring</a></li></ul>
</div>
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-Netty相关概念" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2016/11/04/Netty相关概念/" class="article-date">
<time datetime="2016-11-04T02:13:00.000Z" itemprop="datePublished">2016-11-04</time>
</a>
</div>
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2016/11/04/Netty相关概念/">Netty相关概念</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<h1 id="Netty相关概念">Netty相关概念</h1><p>Netty是一款java实现的nio高并发高性能网络通讯架构,基于事件的管道式架构设计。<br><em>一句话说下:Event(事件)经过Pipeline(管道)中流转通过pipelinesink交给相应的Handler进行处理</em><br><em>发生什么事,找相应的处理方法</em>。<br><figure class="highlight lasso"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">graph LR</span><br><span class="line">Channel-<span class="subst">-></span>|ChannelEvent|ChannelPipeline</span><br><span class="line">ChannelPipeline-<span class="subst">-></span>|ChannelEvent|ChannelHandle1</span><br><span class="line">ChannelHandle1-<span class="subst">-></span>ChannelHandle2</span><br><span class="line">ChannelHandle2-<span class="subst">-></span><span class="attribute">...</span></span><br></pre></td></tr></table></figure></p>
<hr>
<p><a href="http://netty.io/4.1/api/index.html" target="_blank" rel="external">Netty API</a> </p>
<h6 id="Reactor模式">Reactor模式</h6><p>Reactor模式首先是事件驱动的,有一个或多个并发输入源,有一个Service Handler,有多个Request Handlers;这个Service Handler会同步的将输入的请求(Event)多路复用的分发给相应的Request Handler</p>
<h6 id="Bootstrap">Bootstrap</h6><p>框架的启动类。<br>bossGroup<eventloopgroup>:分配任务的线程池,主要负责连接的建立<br>workerGroup<eventloopgroup>:处理任务的线程池,主要负责数据的接收、发送,处理数据读写等具体事件,并保证同一个连接在同一个线程中完成这两个步骤。</eventloopgroup></eventloopgroup></p>
<h6 id="Channel">Channel</h6><p>全局管理器,获取一些全局信息及配置信息,Channel包含Channelpiple</p>
<h6 id="ChannelPipeline">ChannelPipeline</h6><p>通讯管道,存放handler的容器,并有序的组织起来。他是控制ChannelEvent事件分发和传递的。<br><figure class="highlight gherkin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line"> I/O Request</span><br><span class="line"> via Channel or</span><br><span class="line"> ChannelHandlerContext</span><br><span class="line"> |<span class="string"></span><br><span class="line">+---------------------------------------------------+---------------+ </span><br><span class="line"></span>|<span class="string"> ChannelPipeline </span>|<span class="string"> </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> \</span>|<span class="string">/ </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> +----------------------------------------------+----------+ </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> </span>|<span class="string"> Channel Handler N </span>|<span class="string"> </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> +----------+-----------------------------------+----------+ </span>|</span><br><span class="line">|<span class="string"> /</span>|<span class="string">\ </span>|<span class="string"> </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> </span>|<span class="string"> \</span>|<span class="string">/ </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> +----------+-----------------------------------+----------+ </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> </span>|<span class="string"> Channel Handler N-1 </span>|<span class="string"> </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> +----------+-----------------------------------+----------+ </span>|</span><br><span class="line">|<span class="string"> /</span>|<span class="string">\ . </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> . . </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> ChannelHandlerContext.fireIN_EVT() ChannelHandlerContext.OUT_EVT()</span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> [ method call] [method call] </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> . . </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> . \</span>|<span class="string">/ </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> +----------+-----------------------------------+----------+ </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> </span>|<span class="string"> Channel Handler 2 </span>|<span class="string"> </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> +----------+-----------------------------------+----------+ </span>|</span><br><span class="line">|<span class="string"> /</span>|<span class="string">\ </span>|<span class="string"> </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> </span>|<span class="string"> \</span>|<span class="string">/ </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> +----------+-----------------------------------+----------+ </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> </span>|<span class="string"> Channel Handler 1 </span>|<span class="string"> </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> +----------+-----------------------------------+----------+ </span>|</span><br><span class="line">|<span class="string"> /</span>|<span class="string">\ </span>|<span class="string"> </span>|</span><br><span class="line">|<span class="string"> </span>|<span class="string"> \</span>|<span class="string">/ </span>|</span><br><span class="line">|<span class="string"> </span>|<span class="string"> +-----------+----------+ </span>|</span><br><span class="line">|<span class="string"> </span>|<span class="string"> </span>|<span class="string"> ChannelSink </span>|<span class="string"> </span>|</span><br><span class="line">|<span class="string"> </span>|<span class="string"> +-----------+----------+ </span>|</span><br><span class="line">|<span class="string"> </span>|<span class="string"> </span>|<span class="string"> </span>|<span class="string"> </span><br><span class="line">+---------------+-----------------------------------+---------------+ </span><br><span class="line"> </span>|<span class="string"> \</span>|<span class="string">/ </span><br><span class="line">+---------------+-----------------------------------+---------------+ </span><br><span class="line"></span>|<span class="string"> </span>|<span class="string"> </span>|<span class="string"> </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> [ Socket.read() ] [ Socket.write() ] </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> </span>|<span class="string"> </span><br><span class="line"></span>|<span class="string"> Netty Internal I/O Threads (Transport Implementation) </span>|<span class="string"> </span><br><span class="line">+-------------------------------------------------------------------+ </span><br><span class="line">/**</span><br><span class="line">outbound[ Socket.write() ]:输出/写入流 倒序</span><br><span class="line">inbound[ Socket.read() ] :输入/读取流 正序</span><br><span class="line">eg:</span><br><span class="line">ChannelPipeline p = ...</span><br><span class="line">p.addLast("1", new InboundHandlerA());</span><br><span class="line">p.addLast("2", new InboundHandlerB());</span><br><span class="line">p.addLast("3", new OutboundHandlerA());</span><br><span class="line">p.addLast("4", new OutboundHandlerB());</span><br><span class="line">p.addLast("5", new InboundOutboundHandlerX());</span><br><span class="line"></span><br><span class="line">5实现了ChannelInboundHandler和ChannelOutboundHandler,</span><br><span class="line">如果34 不实现 ChannelInboundHandler,则inbound事件顺序是1,2,5</span><br><span class="line">如果12 不实现 ChannelOutboundHandler,则outbound事件顺序是 5,4,3</span><br><span class="line">**/</span></span><br></pre></td></tr></table></figure></p>
<p>==++注意:ChannelPipeline的所有方法都是线程安全的++==</p>
<p>总结:每个连接对应一个ChannelPipeline,ChannelPipeline维护了一个处理链,并提供了丰富的操作处理链的api。 处理链维护了一些列ChannelContext,其中head和tail由ChannelPipeline自己维护,用户无法修改这两个节点。每个ChannelContext包含一个ChannelHandler,所有ChannelContext是私有的线程安全的,但handler可以通过添加注解Sharable的方式来共享。ChannelPipeline提供了一系列操作TailContext和HeadContext的方法来达到处理handler的目的,但操作是由ChannelContext触发ChannelHandler完成的,而非直接操作handler。 </p>
<h6 id="EventLoop">EventLoop</h6><p>主要为Channel处理IO操作,可以同时为多个channel提供服务</p>
<h6 id="EventLoopsGroup">EventLoopsGroup</h6><p>线程池包含多个EventLoop</p>
<h6 id="Channel-1">Channel</h6><p>表示一个Socket链接,和EventLoop一起处理IO。<br>一个channel会对应一个EventLoop,而一个EventLoop会对应一个线程,具体的线程使用交给EventLoopsGroup负责。</p>
<h6 id="ChannelHandlerContext">ChannelHandlerContext</h6><p>pipleline与handler的连接桥梁,ChannelPipeline通过维护ChannelHandlerContext来对ChannelHandler进行维护,每一个ChannelPipeline的节点都是一个ChannelHandlerContext,因此被认为是私有的并且是线程安全的。一个ChannelHandlerContext只能对应一个ChannelHander,只对应一个Channel,而一个ChannelHander则可以对应多个ChannelHandlerContext。</p>
<p>每一个请求都会创建ChannelPipeline,ChannelPipeline内部包含一个有ChannelHandlerContext组成的双向链表,context通过handler的skipFlags来查找下一个inbound/outbound,而具体的调用则通过invoker来完成,invoker保证了调用的线程安全,最终线程安全的调用了handler中的具体方法。<br> context主要负责inbound/outbound事件的传递,由于context不会共用,还可以安全的存储自定义信息(见AttributeMap)</p>
<h6 id="ChannelHandler">ChannelHandler</h6><p>事件处理的节点,每个事件到了handler这里就要被处理了,两个节点的切换是靠channelevent来完成的,一般我们在这里写一些逻辑。</p>
<h6 id="ChannelInboundHandler">ChannelInboundHandler</h6><p>主要处理读操作,可以用来处理核心逻辑</p>
<table>
<thead>
<tr>
<th>方法</th>
<th>对应事件</th>
</tr>
</thead>
<tbody>
<tr>
<td>ChannelHandlerContext#fireChannelRegistered()</td>
<td>注册连接</td>
</tr>
<tr>
<td>ChannelHandlerContext#fireChannelUnregistered()</td>
<td>取消注册</td>
</tr>
<tr>
<td>ChannelHandlerContext#fireChannelActive()</td>
<td>连接激活</td>
</tr>
<tr>
<td>ChannelHandlerContext#fireChannelRead(Object)</td>
<td>读取数据</td>
</tr>
<tr>
<td>ChannelHandlerContext#fireChannelReadComplete()</td>
<td>读取完成</td>
</tr>
<tr>
<td>ChannelHandlerContext#fireExceptionCaught(Throwable)</td>
<td>发生异常</td>
</tr>
<tr>
<td>ChannelHandlerContext#fireUserEventTriggered(Object)</td>
<td>用户事件触发</td>
</tr>
<tr>
<td>ChannelHandlerContext#fireChannelWritabilityChanged()</td>
<td>可写状态改变</td>
</tr>
<tr>
<td>ChannelHandlerContext#fireChannelInactive()</td>
<td>检测到连接断开</td>
</tr>
</tbody>
</table>
<h6 id="ChannelOutboundHandler">ChannelOutboundHandler</h6><p>主要处理写操作</p>
<table>
<thead>
<tr>
<th>方法</th>
<th>对应事件</th>
</tr>
</thead>
<tbody>
<tr>
<td>ChannelHandlerContext#bind(SocketAddress, ChannelPromise)</td>
<td>绑定端口</td>
</tr>
<tr>
<td>ChannelHandlerContext#connect(SocketAddress, SocketAddress, ChannelPromise)</td>
<td>发起连接</td>
</tr>
<tr>
<td>ChannelHandlerContext#write(Object, ChannelPromise)</td>
<td>写数据</td>
</tr>
<tr>
<td>ChannelHandlerContext#flush()</td>
<td>将写的数据发送</td>
</tr>
<tr>
<td>ChannelHandlerContext#read()</td>
<td>触发读操作</td>
</tr>
<tr>
<td>ChannelHandlerContext#disconnect(ChannelPromise)</td>
<td>与对方的连接断开</td>
</tr>
<tr>
<td>ChannelHandlerContext#close(ChannelPromise)</td>
<td>关闭自己的连接</td>
</tr>
<tr>
<td>ChannelHandlerContext#deregister()</td>
<td>触发取消注册</td>
</tr>
</tbody>
</table>
<h6 id="ChannelEvent">ChannelEvent</h6><p>通讯事件,是数据或者状态的载体,对Channel进行操作时会产生一个event,并发送到pipleline。piple会选择一个handler进行处理,处理之后可能会产生新的event,并流转到下个handler。</p>
<h6 id="Future">Future</h6><p>在Netty中所有的IO操作都是异步的,因此无法立刻得知消息是否被正确处理,但是我们可以过一会等它执行完成或者直接注册一个监听,具体的实现就是通过Future和ChannelFutures,他们可以注册一个监听,当操作执行成功或失败时监听会自动触发。总之,所有的操作都会返回一个ChannelFuture。</p>
</div>
<div class="article-info article-info-index">
<div class="article-category tagcloud">
<a class="article-category-link" href="/categories/Java服务器/">Java服务器</a>
</div>
<div class="article-tag tagcloud">
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Netty/">Netty</a></li></ul>
</div>
<div class="clearfix"></div>
</div>
</div>
</article>
<nav id="page-nav">
<span class="page-number current">1</span><a class="page-number" href="/page/2/">2</a><a class="page-number" href="/page/3/">3</a><span class="space">…</span><a class="page-number" href="/page/17/">17</a><a class="extend next" rel="next" href="/page/2/">Next »</a>
</nav>
</div>
<footer id="footer">
<div class="outer">
<div id="footer-info">
<div class="footer-left">
© 2016 M
</div>
<div class="footer-right">
All rights reserved power by <a href="http://www.zhouming.org/" target="_blank">M</a>
<!-- 原版暂存 -->
<!-- <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/luuman/hexo-theme-spfk" target="_blank">spfk</a> by luuman -->
</div>
</div>
<div class="visit">
<span id="busuanzi_container_site_pv" style='display:none'>
<span id="site-visit" >到访数:
<span id="busuanzi_value_site_uv"></span>
</span>
</span>
<span>, </span>
<span id="busuanzi_container_page_pv" style='display:none'>
<span id="page-visit">本页阅读量:
<span id="busuanzi_value_page_pv"></span>
</span>
</span>
</div>
</div>
</footer>
</div>
<script src="https://7.url.cn/edu/jslib/comb/require-2.1.6,jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="/js/main.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
var backgroundnum = 24;
var backgroundimg = "url(/background/bg-x.jpg)".replace(/x/gi, Math.ceil(Math.random() * backgroundnum));
$("#mobile-nav").css({"background-image": backgroundimg,"background-size": "cover","background-position": "center"});
$(".left-col").css({"background-image": backgroundimg,"background-size": "cover","background-position": "center"});
})
</script>
<div class="scroll" id="scroll">
<a href="#"><i class="fa fa-arrow-up"></i></a>
<a href="#comments"><i class="fa fa-comments-o"></i></a>
<a href="#footer"><i class="fa fa-arrow-down"></i></a>
</div>
<script>
$(document).ready(function() {
if ($("#comments").length < 1) {
$("#scroll > a:nth-child(2)").hide();
};
})
</script>
<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
</script>
<script language="javascript">
$(function() {
$("a[title]").each(function() {
var a = $(this);
var title = a.attr('title');
if (title == undefined || title == "") return;
a.data('title', title).removeAttr('title').hover(
function() {
var offset = a.offset();
$("<div id=\"anchortitlecontainer\"></div>").appendTo($("body")).html(title).css({
top: offset.top - a.outerHeight() - 15,
left: offset.left + a.outerWidth()/2 + 1
}).fadeIn(function() {
var pop = $(this);
setTimeout(function() {
pop.remove();
}, pop.text().length * 800);
});
}, function() {
$("#anchortitlecontainer").remove();
});
});
});
</script>
</div>
</body>
</html>