`
sh2015yao
  • 浏览: 136014 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

使用.net-Synchronized属性进行静态方法的同步

阅读更多

使用.net属性进行静态方法的同步
本文介绍使用.net得Synchronized属性实现线程的同步.
Synchronized毋庸置疑,可以方便的实现instance level的方法同步,但是是否同样适用于static方法呢?本文写了下面的代码进行验证。结果令人满意,确实可以实现静态方法的同步。

 

[MethodImpl(MethodImplOptions.Synchronized)]
    public static bool AppJobDelete(int id)
    {
        bool flag = true;
        try
        {
            string sql = "delete from Appjob where id=@id";
            SqlCommand command = new SqlCommand(sql, getConnection());
            command.Parameters.AddWithValue("@id", id);
            command.ExecuteNonQuery();
        }
        catch (Exception e)
        {
            flag = false;
        }
        return flag;
    }

 

 java的线程同步同步参考:

http://arthennala.blog.51cto.com/287631/56356 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics