在Java/Eclipse中,为什么在代码中设置断点会改变该语句的效果? [英] In Java/Eclipse, why does setting a breakpoint in my code alter the effect of that statement?

查看:67
本文介绍了在Java/Eclipse中,为什么在代码中设置断点会改变该语句的效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Eclipse编写一个Android应用程序,并使用 TextView 在屏幕上显示一些文本.有时,其他线程会使用以下代码更改此视图的文本:

I'm writing an Android app in Eclipse, and displaying some text on screen using a TextView. A different thread sometimes changes the text of this view, with the following code:

runOnUiThread(new Runnable() {

    @Override
    public void run() {
        view.setText(newLyric);
    }
});

我想调试 setText 行,以检查是否传入了正确的String(对于某些文本,没有将其自动换行以适合屏幕,对于其他文本,则为是,但这是一个不同的问题).当我在该行上放置断点时,文字总是被 换行.而且当我禁用/删除断点时,通常不会自动换行(确定性)的文本不会自动换行.

I wanted to debug the setText line to check that the correct String was being passed in (as for some text, it was not being word-wrapped to fit the screen, and for other text it was, but that's a different issue). When I put a breakpoint on that line, the text is always word-wrapped. And when I disable/remove the breakpoint, the text that usually doesn't get word-wrapped (it's deterministic) is not word-wrapped.

这对我来说没有多大意义.我已经看到这个问题,并且我理解背后的原因,但我不明白为什么这会是这里的问题.谁能对此有所启发?我正在设备上进行测试,如果有什么区别.

This doesn't make much sense to me. I've seen this question, and I understand the reasoning behind that, but I can't see why that would be the issue here. Can anyone shed some light on this? I'm testing on a device, if that makes any difference.

事实证明,这是一个竞赛条件,现在我只需要解决该问题.显然,我只能选择一个正确"的答案,但是谢谢您.谢谢大家的宝贵意见:)

It turns out it was a race condition, now I just have to work out how to fix it... Obviously I could only pick one 'correct' answer, but thank you to all of you for the helpful comments :)

推荐答案

类似的东西有时有时/经常表明比赛条件.

Things like this are sometimes/often a sign of a race condition.

放置一个断点可以消除竞争(因此,作为一个示例,一个通过稍后运行来覆盖该值的流氓"线程现在在捕获断点时就已经完成了.)

Putting a breakpoint eliminates the race (so a "rogue" thread that was overriding the value by running later is now finished by the time your breakpoint is caught, as an example).

或者这是 Heisenbug 的明显案例:)

Or it's a clear case of Heisenbug :)

这篇关于在Java/Eclipse中,为什么在代码中设置断点会改变该语句的效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆