<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont

本文涉及的产品
转发路由器TR,750小时连接 100GB跨地域
简介: #!/usr/bin/pythonimport Queueimport timeimport threadingq=Queue.
#!/usr/bin/python
import Queue
import time
import threading

q=Queue.Queue()

class producer(threading.Thread):
    def __init__(self,i):
        threading.Thread.__init__(self,name="producer Thread-%d" % i)
    def run(self):
        global q
        count=9
        while True:
            for i in range(3):
                if q.qsize() > 12:
                    pass
                else:
                    count=count+1
                    msg=str(count)
                    q.put(msg)
                    print self.name+' '+'producer'+msg+' '+'Queue Size:'+str(q.qsize())
                    
            time.sleep(2)

class consumer(threading.Thread):
    def __init__(self,i):
        threading.Thread.__init__(self,name="consumer Thread-%d" % i)
    def run(self):
        global q
        while True:
            for i in range(3):
                if q.qsize() < 1:
                    pass
                else:
                    msg=q.get()
                    print self.name+' '+'consumer'+msg+' '+'Queue Size:'+str(q.qsize())
            time.sleep(2)


def test():
    for i in range(10):
        q.put(str(i))
        print 'Init producer  '+str(i)
    for i in range(2):
        p=producer(i)
        p.start()
    for i in range(3):
        c=consumer(i)
        c.start()

if __name__ == '__main__':
    test()
生产者消费者模型
目录
相关文章
|
存储 Web App开发 监控
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
我们以前使用过的对hbase和hdfs进行健康检查,及剩余hdfs容量告警,简单易用 1.针对hadoop2的脚本: #/bin/bashbin=`dirname $0`bin=`cd $bin;pwd`STATE_OK=...
1070 0
|
Web App开发 前端开发 算法
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
import java.util.LinkedHashMap;import java.util.Map; /** * LRU (Least Recently Used)  */public class LRUCache e...
641 0
|
Web App开发 存储 前端开发
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
做大做强事实表,做小做弱维表; 分布式模式-维度建模新原则  (1)以值代键:针对键值唯一的维表,除非必要,否则不引入维表,如IP地址维表,采用IP作为维表的主键,事实表中存储IP值;      (2)合理分表:传统关系型数据仓库存在多表整合的冲动,如上图Event事实表,各种Acount Ind,Finance Ind等,用来扩展表的通用性,试图把所有的数据都存储到一张表 中。
797 0
|
Web App开发 Java Apache
|
Web App开发 前端开发 API
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
     比如RDD里的计算调用了别的组件类里的方法(比如hbase里的put方法),那么序列化时,会将该方法所属的对象的所有变量都序列化的,可能有些根本没有实现序列化导致直接报错。
748 0
|
Apache
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
我测试是在windows7上测测试的, 需要准备的软件列表如: a. Apache2.2b. apache-tomcat-6.
1310 0
|
Web App开发 前端开发 安全
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
1 这是北京交通大学的镜像站:http://mirror.bjtu.edu.cn/cn/ 2 这个站点有一个好处就是他不仅是操作系统的镜像站而且还要一写其他常用软件的仓库,   如Apache的常用软件 hbase 和hive等,http://mirror.
937 0
|
Java Apache
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><meta http-equiv="Cont
在该文档中,我将带领大家使用基于JAX-RS REST风格的实现Jersey来上传文件到服务器制定的文件夹,如果是图片并读取显示出该图片。
1451 0