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. 2-sat学习笔记

    前后缀建图 例:要求n个变量满足至多有1个为true. 暴力:一个点的true向其它n-1个点的false连边,复杂度O(n^2). 正解:prei表示前i个点是否有真. prei的true向prei ...

  2. KDD Cup 99网络入侵检测数据的分析

    看论文 该数据集是从一个模拟的美国空军局域网上采集来的 9 个星期的网络连接数据, 分成具有标识的训练数据和未加标识的测试数据.测试数据和训练数据有着不同的概率分布, 测试数据包含了一些未出现在训练数 ...

  3. NIM 博弈 牛客小白月赛2 E-是是非非

    题目链接 分析:一个裸的NIM博弈 对于一个Nim游戏的局面(a1,a2,...,an),它是P-position(即当前局面先手必败)当且仅当a1^a2^...^an=0,其中^表示异或(xor)运 ...

  4. js定义类

    以下是es5标准里定义类的方法: function Point(x,y){ this.x=x; this.y=y; } Point.prototype.toString=function(){ ret ...

  5. 我的第一个C语言程序

    从自学开始到现在应该有块一个月了,之前一直想要写博客一直没想好要自己建博客还是找平台来写.现在想想 其实都一样,不论在哪里,都可以记录自己学习的成长记录.这是我的第一篇关于C语言学习的博客,希望这只是 ...

  6. vs 2017 Integrated Security 为sspi 含义

    关于sql连接语句中的Integrated Security=SSPI解决方法:即:Security Support Provider Interface设置Integrated Security为 ...

  7. 十五、MVC的WEB框架(Structs2)

    一.Structs标签 与JSTL标签库类似,Structs2也有专属标签库 常见的标签有:from,iterator,check,radio,select 1.form标签 用于提交数据 <% ...

  8. provider和consumer配置参数的优先级

    <dubbo:service>和<dubbo:reference>存在一些相同的参数,例如:timeout,retries等,那么哪个配置的优先级高呢? consumer合并u ...

  9. notepad++自动对齐使用空格代替Tab并将空格显示为小点

    一.说明 对大多数语言而言自动对齐使用空格还是tab对编译运行并没有什么影响,但对python问题就很大:因为就算是缩进看起来是一样的但某些行用空格某些行用tab运行会报错. 另外除了空格替换tab外 ...

  10. kali-rolling安装openvas 9并创建扫描任务教程

    一. 前置说明 官方:漏洞扫描中最常用和强大的是某个”N“开头的漏洞扫描器(nessus),但由于许可证限制,kali中并未安装该漏洞扫描器.取而代之安装了nessus收费之后发起的开源版本openv ...