同步两种方法

扫码查看
本文介绍了同步两种方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

有什么办法可以同步两种方法?示例:

Hi everybody,

Is there any way to synchronize two methods? Example:

public class myclass
{
     private int x;
     public void method1()
     {
          //Access to x from thread1
     }

     public void method2()
     {
          //Access to x from thread2
     }
}



为此,method1()和method2()将从其他线程访问x.有什么方法可以使它们同步(一次只有一种方法可以访问变量x)?



There for, method1() and method2() will access to x from other threads. Is there any way to synchronize them (just one method can access variable x at a time)?

推荐答案


这篇关于同步两种方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 15:08
查看更多