- 博客(75)
- 资源 (1)
- 收藏
- 关注
原创 java8语法
java8语法 public void test2(){ //员工集合 List <Employee> emps = Arrays.asList( new Employee("张三",12,200.0), new Employee("李四",23,200.0), ...
2018-02-25 21:28:24
494
1
原创 es6语法
函数的默认传参function func(firstname='martin',lastname='kin') { return `${firstname},${lastname}`;}console.log(func('zs'));输出 zs,kin
2017-11-21 21:29:47
478
1
原创 es6新语法
es6新语法“` function createMesh() { return {‘fistname’:’martin’,’lastname’:’wang’}; }let {fistname:fisrt,lastname:last} = createMesh();console.log(last); console.log(fisrt);输出结果wang martin
2017-11-21 21:03:31
355
原创 python 中的队列
queue 可以保证每个线程取和存数据的安全性,因为它里面实现了锁机制#-*-coding:utf-8-*- #__author:martin#date:2017/10/23import threadingimport randomimport timeclass Producer(threading.Thread): def run(self): globa
2017-10-24 22:01:53
338
原创 python 生产者和消费者
#-*-coding:utf-8-*- #__author:martin#date:2017/10/23import threadingimport randomimport timeclass Producer(threading.Thread): def run(self): global L while True:
2017-10-23 22:04:18
487
原创 lambda表达式
package com.brendan.cn.java8;import java.util.ArrayList;import java.util.Arrays;import java.util.List;import java.util.function.Predicate;public class TestMain { public static void main(String[]
2017-10-23 21:03:13
232
转载 phaser
创建三个线程在三个目录里查找一天以内修改过的以log结尾的文件并打印出来, 线程与线程之间通过phaser来保持同步点package com.brendan.cn.concurrent.phaser;import java.io.File;import java.util.ArrayList;import java.util.Date;import java.util.List;impor
2017-10-23 20:51:43
246
原创 TreeMap
import java.util.Comparator;import java.util.Map;import java.util.TreeMap;public class TestTreeMap { public static void main(String[] args) { new TestTreeMap().test(); } void tes
2017-10-23 20:11:47
184
原创 ArrayBlockingQueue
public class TestArrayBlockingQueue { public static void main(String[] args) throws InterruptedException { BlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(3); for(int i
2017-10-23 20:10:33
181
原创 cyclicBarrier
import java.util.concurrent.BrokenBarrierException;import java.util.concurrent.CyclicBarrier;public class TestCyclicBarrier { public static void main(String[] args) throws InterruptedException, Br
2017-10-23 20:07:09
344
原创 deadLock
public class DeadLock { private static Object o1 = new Object(); private static Object o2 = new Object(); public static void main(String[] args) { new Thread(()->{
2017-10-23 20:04:49
283
原创 jion
public class TestJoin { public static void main(String[] args) { MyThread2 t1 = new MyThread2("TestJoin"); t1.start(); try { t1.join(); //join()合并线程,子线程运行完之后,主线程才
2017-10-23 20:03:47
517
原创 python 中的semaphore
控制并发的线程数#-*-coding:utf-8-*- #__author:martin#date:2017/10/22import threadingimport timeclass Mythread(threading.Thread): def run(self): if semaphore.acquire(): print(self.na
2017-10-22 20:03:03
937
原创 python线程
创建两个线程,并运行#-*-coding:utf-8-*-#__author:martin#date:2017/10/22import threadingclass Mythread(threading.Thread): def __init__(self,num): threading.Thread.__init__(self) self.num =
2017-10-22 11:09:47
210
原创 python中线程和进程
1.进程是cpu资源分配的最小单位,线程是cpu调度的最小单位 2.一个进程里可以包含多个线程,线程之间可以直接通讯,每个线程都有自己的线程栈,并可以访问线程属于的进程的资源。而进程通讯要通过其他的方式,比如队列等等 3.创建线程开销小,创建进程开销大 4.在python中,由于有全局解释器锁(GIL)的原因,同一时刻一个进程下的线程只能分配给一个cpu去执行。所以python适合的是IO密集
2017-10-22 09:04:05
294
原创 python中的socketserver
socketserver 实际上是为了简化socket编程#-*-coding:utf-8-*- #__author:martin#date:2017/10/21import socketimport socketserverclass MyServer(socketserver.BaseRequestHandler): def handle(self): print
2017-10-21 20:28:04
436
原创 python编码解码
#-*-coding:utf-8-*- #__author:martin#date:2017/10/21s = 'hello可乐'#编码 str类型 ---> 16进制bytes类型b = s.encode('utf8')print(type(b))print(b)#b'hello\xe8\x99\x8e'#解码 16进制bytes类型--->str类型 s_n = str(b
2017-10-21 16:02:45
457
原创 python中的单例
#-*-coding:utf-8-*- #__author:martin#date:2017/10/19class Foo: __v = None @classmethod def getInstance(cls): if cls.__v: return cls.__v else: cls.
2017-10-19 20:53:43
290
原创 python类名()的执行过程
#-*-coding:utf-8-*- #__author:martin#date:2017/10/18class MyType(type): def __init__(self,*args,**kwargs): print("遇到类名....") def __call__(self, *args, **kwargs): print('类名加()
2017-10-18 21:14:22
1496
转载 IntelliJ IDEA 15 创建maven项目
IntelliJ IDEA 15 创建maven项目 <div class="postBody"> <div id="cnblogs_post_body"><h1 id="autoid-0-0-0">说明</h1>创建Maven项目的方式:手工创建好处:参考IntelliJ IDEA 14 创建maven项目二(此文章描述了用此方式创建Ma
2017-10-17 20:15:11
287
原创 python 面向对象继承
#-*-coding:utf-8-*- #__author:martin#date:2017/10/15class F: def f1(self): print('F.f1')class S(F): def f1(self): #super(S,self).f1() #执行父类的方法,第一种方式,常用这种方式 F.f1(self)
2017-10-15 09:36:58
192
原创 python 使用json模块
#-*-coding:utf-8-*- #__author:martin#date:2017/10/14import json# dic = {'name':'martin','age':20}# data = json.dumps(dic)# f = open('test.txt','w')# f.write(data)# f.close()f = open('test.txt','
2017-10-14 09:27:22
250
转载 httpclient工具类
http发送post ,get请求的工具类import java.io.IOException;import java.net.URL;import java.util.ArrayList;import java.util.List;import java.util.Map;import org.apache.http.NameValuePair;import org.apache.htt
2017-10-12 21:10:49
301
原创 python 利用正则实现简易计算器
#-*-coding:utf-8-*-#__author:martin#date:2017/10/11import redef f_string(s): s = s.replace(' ','') s = s.replace('++', '+') s = s.replace('--', '+') s = s.replace('+-', '-') return
2017-10-11 23:05:55
589
原创 python 中的正则
匹配数字 \d,字符符号\w,空白符号\s,特殊边界\b# ret = re.findall('\d+','12344eee')# print(ret)# ret = re.findall('\smart',' ad mart')# print(ret)# ret = re.findall('\w',' ad mart')# print(ret)# ret = re.findall(r'm\b
2017-10-10 21:54:10
366
原创 python记录日志
#-*-coding:utf-8-*- #__author:martin#date:2017/10/9import loggingimport sys#获取logger实例,如果参数为空则返回root loggerlogger = logging.getLogger("AppName")# 指定logger输出格式formatter = logging.Formatter('%(asc
2017-10-09 22:01:04
1959
原创 python 生成器
生成器的作用是边循环边计算,节约内存#定义一个生成器def foo(): print('www') yield 1 print('martin') yield 2#这里得到生成器,并不是执行函数g = foo()for i in g: print(i)www 1 martin 2裴波那契数列def fibo(indx): n ,bef
2017-10-07 14:24:24
159
原创 python 里装饰器
装饰器就是给原理的函数添加新的功能,用到了闭包#需要添加的功能def show_time(fun): def inner(): start = time.time() fun() end = time.time() print(end-start) return inner#功能函数def foo():
2017-10-06 23:04:15
131
原创 python 中的闭包
内部函数引用了外部作用域的变量def outer(): x = 100 def inner(): print(x) return innerouter()()100
2017-10-06 22:07:39
137
原创 python 内置函数
#filterdef fun1(s): if s != 'a': return sstr = ['a','b','c','d']f1 = filter(fun1 , str)print(list(f1))['b', 'c', 'd']#mapstr = ['1','2','3']def fun2(s): return s+'martin'var =
2017-10-06 21:34:03
274
原创 python 里的集合
c1 = set('abc')print(c1)c1.add('zh')print(c1)c2 = set('abc')print(c2)c2.update('zh')print(c2){‘b’, ‘c’, ‘a’} {‘zh’, ‘b’, ‘c’, ‘a’} {‘b’, ‘c’, ‘a’} {‘z’, ‘h’, ‘c’, ‘a’, ‘b’}
2017-10-06 11:59:19
166
原创 python 浅copy 和 深copy
浅copy 只copy第一层第一种情况s = [‘martin’,’decoration’,123] s1 = s.copy() s1[0]= ‘s’ print(s1) print(s)[’s’, ‘decoration’, 123] [‘martin’, ‘decoration’, 123]第二种情况v = [[1,2],3,4] b= v.copy() b[0][0] =
2017-10-05 22:47:27
234
原创 python打印乘法表
i = 1while i <= 9: j = 1 while j <= i : print(j ,"*", i , "=" , j*i,end="\t") j += 1 print() i += 1
2017-10-01 19:30:14
568
原创 python变量赋值
1、python 的安装目录 D:\development\Python362、 将D:\development\Python36 加入到环境变量path ,查看版本 3、在E:\python文件夹里新建一个test.py文件,内容如下name = "jack"name2 = namename = "martin"print(name,name2)4、以管理员身份打开命令行,进入 E
2017-10-01 08:52:01
407
转载 Zookeeper以Windows服务安装运行
Zookeeper以Windows服务安装运行 2016-04-01 18:20 by mrluo735, 2454 阅读, 6 评论, 收藏, 编辑 1.下载的Zookeeper是.cmd的批处理命令运行的,默认没有提供以windows服务的方式运行的方案 下载地址:http://zookeeper.apache.org/ 2.下载prunsrv
2017-09-30 22:37:53
500
原创 synchronous错误使用
i++后对象变化了,所以会出现错误的结果。package com.brendan.cn.concurrent;import java.net.InetAddress;/*************************************************************** * Created by martin on 2017/9/29. *****************
2017-09-29 21:55:20
981
原创 phaser模拟百米赛跑
package com.brendan.cn.concurrent.match;import java.util.concurrent.Phaser;public class Match { // 模拟了100米赛跑,10名选手,只等裁判一声令下。当所有人都到达终点时,比赛结束。 public static void main(String[] args) throws Interru
2017-09-28 21:57:15
493
原创 callable和future
一次提交10个任务去执行,任务执行完从future获取结果package com.brendan.cn.concurrent;import java.util.Random;import java.util.concurrent.*;public class CallableAndFuture { public static void main(String[] args) {
2017-09-23 23:45:32
203
原创 java中创建线程的两种方式
package com.brendan.cn.concurrent;public class TestThread { public static void main(String[] args) { //第一种方式 Thread thread = new Thread(){ @Override public voi
2017-09-20 20:54:30
266
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人