Giter Club home page Giter Club logo

blog's Introduction

blog's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar ramsayleung avatar xwjdsh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

blog's Issues

关于《一条经典面试题引发的思考》的一个问题

您好,我阅读了您的文章《一条经典面试题引发的思考》之后对一些地方有异议,由于没在博客中找到评论的地方,所以冒昧将问题写在了这里,打扰之处,还请谅解。

问题描述

请问 第23行,在 continue 之前是否需要先执行 Unlock 操作。否则可能出现锁资源未释放的情况。

具体分析如下,我们将i的上限从30改成3,这样相当于希望每个线程只执行一次有效操作。

假设有这样的情况,线程 B 执行一次后,线程 C 正在上锁,此时i的值还没改变,线程 B判断i < 3继续循环。线程 C 执行成功后,线程 B加锁成功。此时i变成了3,线程 B 判断i >= 3,结束循环,线程 B 就有了一个加锁的锁资源未释放。

     1  public void Test(){
     2      private static Integer index = 0;
     3      Lock lock = new ReentrantLock(true);
     4      @Test
     5      public void testLock(){
     6              Thread threadA = work(() -> System.out.println("A"));
     7              Thread threadB = work(() -> System.out.println("B"));
     8              Thread threadC = work(() -> System.out.println("C"));
     9              threadA.setName("threadA");
    10              threadA.start();
    11              threadB.setName("threadB");
    12              threadB.start();
    13              threadC.setName("threadC");
    14              threadC.start();
    15              System.out.println();
    16      }
    17
    18      private Thread work(Runnable function) {
    19              return new Thread(() -> {
    20                  while (index.intValue() < 3) {
    21                  lock.lock();
    22                  if (index >= 3) {
    23                      // lock.unlock();
    24                      continue;
    25                  }
    26                  if (condition.test(index.intValue())) {
    27                      function.run();
    28                      index++;
    29                  }
    30                  lock.unlock();
    31                  }
    32              });
    33      }
    34  }

Readme initial login username and password

Hi Ramsay,
The initial login username and password seems not working at the moment. May I ask where can I find the correct one?
BTW, I guess the server port has been changed to 1337.
Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.