首页 \ 问答 \ Java中的哪些操作被认为是原子的?(What operations in Java are considered atomic?)

Java中的哪些操作被认为是原子的?(What operations in Java are considered atomic?)

Java中的哪些操作被认为是原子的?


What operations in Java are considered atomic?


原文:https://stackoverflow.com/questions/4756536
更新时间:2023-08-01 12:08

最满意答案

在java中,您可以使用标签指定要中断/继续的循环:

mainLoop:
while (goal <= 100) {
   for (int i = 0; i < goal; i++) {
      if (points > 50) {
         break mainLoop;
      }
      points += i;
   }
}

In Java you can use a label to specify which loop to break/continue:

mainLoop:
while (goal <= 100) {
   for (int i = 0; i < goal; i++) {
      if (points > 50) {
         break mainLoop;
      }
      points += i;
   }
}

相关问答

更多
  • 将循环放在函数中并使用return关键字: def func(primes): for a in range(3, 500, 2): for b in range(2, int(a ** 0.5 + 0.5)): if a % b != 0: primes.append(a) if a % b == 0: [x for x in primes if x != a] ...
  • 最快的基础解决方案是使用outer : as.vector(outer(B,A,"-")) 令我惊讶的是, map2_dbl实际上比 outer要快得多: 毫不奇怪, map2_dbl看起来更快,但那是因为它没有计算A和B中每个值的组合 : test elapsed relative 3 CP(A, B) 7.54 47.125 # using expand.grid 2 JL(A, B) 0.16 1.000 # using map2_dbl 1 JM(A, B) ...
  • 在java中,您可以使用标签指定要中断/继续的循环: mainLoop: while (goal <= 100) { for (int i = 0; i < goal; i++) { if (points > 50) { break mainLoop; } points += i; } } In Java you can use a label to specify which loop to break/continue: mainLoo ...
  • 至少有建议,但也被拒绝 。 我不认为有另一种方法,不要重复测试或重新组织代码。 有时候有点恼人。 在拒绝信中 ,范罗苏先生提到使用return ,这是真的很明智,我需要记住的一些事情。 :) It has at least been suggested, but also rejected. I don't think there is another way, short of repeating the test or re-organizing the code. It is sometimes a ...
  • AFAIK,C ++不支持命名循环,如Java和其他语言。 您可以使用goto或创建您使用的标志值。 在每个循环结束时检查标志值。 如果设置为true,则可以突破该迭代。 AFAIK, C++ doesn't support naming loops, like Java and other languages do. You can use a goto, or create a flag value that you use. At the end of each loop check the flag ...
  • Suggest me any book or paper on for loops or links!! 为了巩固你对循环2的理解,你可以尝试在http://www.codingbat.com/java练习 - 此外,还有即时和(大部分)彻底的评分! String-3或Array-3问题可以使用2 for循环。 如果你有一个2D数组,并且你需要到达所有的索引,你可以使用2 for循环。 因此,类似地,如果你有一个3D数组,你可以使用3个嵌套循环。 请记住,循环内部在外部之前结束 - 因此,如果您有2个循环, ...
  • 没有一般结果。 这取决于你的系统。 基准测试并获得您自己的结果。 但是利用更多地方的那个往往更快 There's no general result. It depends on your system. Benchmark and get a result for your own. But the one that utilizes more locality is often faster
  • 有一面旗帜,如果旗帜落在他们两个身上。 var flag = true; for(condition && flag) { for (condition && flag) { if(condition) { flag = false; break; } } } Have a flag and if the flag falls break out of both of them. var fl ...
  • 退出两个循环并避免可能遵循最内部循环的任何代码的一个好方法是将循环放入函数中并返回所需的任何值。 for (x=0;x<3;x++) { for (y=0;y<3;y++) { if (z == 1) { return RETURN_VALUE } //avoids this code } //and this one too } A good way to exit both l ...
  • itertools.product()函数应该有帮助: >>> [values for values in product(range(3), repeat=3) if sum(values) == 5] [(1, 2, 2), (2, 1, 2), (2, 2, 1)] 看到答案包含相同答案的字谜,您可以使用itertools.combinations_with_replacement()进一步减少工作: >>> # 4 digits in [0, 1, 2, 3, 4] summing to 6 >> ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。