Overview

  • Background: I start a thread [call thread A below]in Spark driver to handle opening files in codis, in which I start six thread [call sub threads below]to handle the files in parallel.

  • What happened:

    • I found the codis openingFilePool never update since a given time.

    • So I looked into the Thread Dump tools of spark, and saw that thread A is always been WAITING. As below:

    • The normal one is as follow:

    • See the difference?
      The thread should be TIMED_WAITING(sleep), not be WAITING(wait for some other threads to awake it)!
    • It seems there is a deadlock?

  • Thread A get a jedis instance from JedisResourcePool to get all opening files.

  • Then, the sub threads handle these opening files and interact with codis in pipeline. [I use try(Pipeline pipeline = CodisPool.getPool().getResource().pipelined())]

Possible causes

  • I am not sure this is because 1) there is no enough instance in JedisPool; or 2) there is a deadlock?

    • try (Pipeline pipeline = CodisPool.getPool().getResource().pipelined())
      • I am not sure whether this code will close jedis and pipeline, or it will just close pipeline?

    • JedisResourcePool is not thread-safe?

      • Some says that we should sync when we getResource() from JedisResourcePool. I am not sure.

      • And also I think should I configure the number of Jedis pool.

Final words

  • I have been wondering how to check whether the chained resource is closed. Uh... So I raised a question in stackoverflow.
  • Show the amzaing answer:
  • Try-with-resources close only variable, in your case Pipeline pipeline. You can read more in docs https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html

    You can check it with example:

    MyResource class:

    class MyResource implements AutoCloseable {
    
        public SubResource getSubResource() {
    return new SubResource();
    } @Override
    public void close() throws Exception {
    System.out.println("Resource closed");
    }
    }

    SubResource class:

    class SubResource implements AutoCloseable{
    @Override
    public void close() throws Exception {
    System.out.println("SubResource closed");
    }
    }

    Main class:

    class Main {
    
        public static void main(String[] args) {
    try (SubResource s = new MyResource().getSubResource()) {
    System.out.println("Before closing");
    } catch (Exception e) {
    e.printStackTrace();
    } System.out.println("After closing");
    }
    }

    Execution result:

    Before closing
    SubResource closed
    After closing

<Codis><JedisPool><DeadLock>的更多相关文章

  1. 简单物联网:外网访问内网路由器下树莓派Flask服务器

    最近做一个小东西,大概过程就是想在教室,宿舍控制实验室的一些设备. 已经在树莓上搭了一个轻量的flask服务器,在实验室的路由器下,任何设备都是可以访问的:但是有一些限制条件,比如我想在宿舍控制我种花 ...

  2. 利用ssh反向代理以及autossh实现从外网连接内网服务器

    前言 最近遇到这样一个问题,我在实验室架设了一台服务器,给师弟或者小伙伴练习Linux用,然后平时在实验室这边直接连接是没有问题的,都是内网嘛.但是回到宿舍问题出来了,使用校园网的童鞋还是能连接上,使 ...

  3. 外网访问内网Docker容器

    外网访问内网Docker容器 本地安装了Docker容器,只能在局域网内访问,怎样从外网也能访问本地Docker容器? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动Docker容器 ...

  4. 外网访问内网SpringBoot

    外网访问内网SpringBoot 本地安装了SpringBoot,只能在局域网内访问,怎样从外网也能访问本地SpringBoot? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装Java 1 ...

  5. 外网访问内网Elasticsearch WEB

    外网访问内网Elasticsearch WEB 本地安装了Elasticsearch,只能在局域网内访问其WEB,怎样从外网也能访问本地Elasticsearch? 本文将介绍具体的实现步骤. 1. ...

  6. 怎样从外网访问内网Rails

    外网访问内网Rails 本地安装了Rails,只能在局域网内访问,怎样从外网也能访问本地Rails? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动Rails 默认安装的Rails端口 ...

  7. 怎样从外网访问内网Memcached数据库

    外网访问内网Memcached数据库 本地安装了Memcached数据库,只能在局域网内访问,怎样从外网也能访问本地Memcached数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装 ...

  8. 怎样从外网访问内网CouchDB数据库

    外网访问内网CouchDB数据库 本地安装了CouchDB数据库,只能在局域网内访问,怎样从外网也能访问本地CouchDB数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动Cou ...

  9. 怎样从外网访问内网DB2数据库

    外网访问内网DB2数据库 本地安装了DB2数据库,只能在局域网内访问,怎样从外网也能访问本地DB2数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动DB2数据库 默认安装的DB2 ...

  10. 怎样从外网访问内网OpenLDAP数据库

    外网访问内网OpenLDAP数据库 本地安装了OpenLDAP数据库,只能在局域网内访问,怎样从外网也能访问本地OpenLDAP数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动 ...

随机推荐

  1. p1468 Party Lamps

    就是模拟.同一个开关按2下相当于没按,那么,如果一共按0下,就是没按,按1下就是4个开关的1个,按2下可能相当于实际按了0下或按2下,按3下实际按了1下或3下,之后如果是奇数,相当于按1或3下,偶数相 ...

  2. scrapy-redis(一)

    安装scrapy-redis pip install scrapy-redis 从GitHub 上拷贝源码: clone github scrapy-redis源码文件 git clone https ...

  3. PHP工厂模式demo

    <?php//工厂模式 interface operstion{ function oper($a,$b);}//加class add implements operstion{ functio ...

  4. Python----list&元祖常用方法总结

    一.创建列表,把使用逗号分隔的数据用中括号[  ]括起来即为一个列表,列表也叫数组.list.array:列表里面也可以再套列表,一个列表里面套一个列表,叫二维数组:一个里面套一个列表,里面的列表再套 ...

  5. [CodeForces - 447D] D - DZY Loves Modification

    D - DZY Loves Modification As we know, DZY loves playing games. One day DZY decided to play with a n ...

  6. easyUI的form表单重复提交处理

    1. 问题 生产环境出现过新增用户提交, 入库两条重复数据的情况; 但是我查看代码, 页面做了校验, 后台插入数据也做了校验;  出现这种几率的事件的非常小的, 但是还是会碰到, 客户会对我们的产品产 ...

  7. springmvc静态资源处理

    1.配置springmvc拦截规则,注意不能拦截 /*,这样的话,会对所有请求默认拦截,而应该拦截 /, 这样servlet会先走默认的拦截规则,默认拦截规则找不到后,才会走 / 这个规则,这样静态资 ...

  8. vim 文本会在末尾自动添加换行 md5文件和数据只不对应

    在linux系统 vim md5data  # 打开文件 写入 abc 保存 md5sum md5Data  的计算值和openssl代码计算值不一样 原因在于linux文本文件末尾自动添加了换行 解 ...

  9. eclipse安装springboot插件

    1.工具栏->Help->Eclise Marketplace打开应用市场 2.在应用市场中搜索sts,选择Spring Tools 4紧张安装 3.按提示进行安装

  10. nodejs安装 淘宝镜像

    1◆ nodejs下载 2◆ 安装 3◆ 测试   4◆ 淘宝镜像 npm install -g cnpm --registry=https://registry.npm.taobao.org   5 ...