zoukankan      html  css  js  c++  java
  • 一道java多线程的笔试题,难到我了,大家看看。

    Given:                        
    1. public class SyncTest {                       
    2. private int x;                       
    3. private int y;                       
    4. private synchronized void setX( int i ) { x = i; }                       
    5. private synchronized void setY( int i ) { y = i; }                   
    6. public void setXY( int i ) { setX(i); setY(i); }                   
    7. public synchronized boolean check() { return x != y; }                   
    8. }                   
    Under which condition will check return true when called from a different class?                   
    A. check can never return true.                   
    B. check can return true when setXY is called by multiple threads.                   
    C. check can return true when multiple threads call setX and setY separately.                   
    D. check can return true only if SyncTest is changed to allow x and y to be set separately.                   
          本人在B和C之间犹豫。

  • 相关阅读:
    leetcode刷题笔记十四 最长公共前缀 Scala版本
    leetcode刷题笔记十三 罗马数字转数字 Scala版本
    leetcode刷题笔记十二 整数转罗马数字 Scala版本
    Maven 安装与配置
    Maven基础
    java 打jar包配置文件和jar包通级
    java 类
    java 数组
    java 重载
    java 普通项目的配置文件
  • 原文地址:https://www.cnblogs.com/SunnyYue/p/3970300.html
Copyright © 2011-2022 走看看