净静态方法,它是对并发的影响? [英] .Net Static Methods and it's effects on Concurrency?

查看:124
本文介绍了净静态方法,它是对并发的影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在建设将要使用的Web服务的API。

I am currently building an API which will be used by a webservice.

我想知道什么性能问题,我能应付,如果我建我的API使用了大量的静态方法

I was wondering what performance issues I could meet if I built my API using a large amount of static methods.

最初的想法是建立充当服务专家的对象。

The original idea was to build expert objects which act as services.

在单用户环境中这种方法是伟大的! 但我很快就需要端口这一个多/并发用户的环境。

In a single user environment this approach was great! But I will soon need to port this to a multi/concurrent user environment.

可能我遇到这种体系结构是什么样的性能问题?

What kind of performance issues might i encounter with this kind of architecture?

最好的问候,

编辑:

静态方法容不下静态变量和没有任何副作用。他们只是执行常规正常,一切都是实例。 (即VAR和对象)

The static methods hold no static variables and have no side effects. They simply execute a normal routine where everything is instantiated. (ie. vars and objects)

推荐答案

有一个关于并发性没有特别的影响。同样的规则为真:变异的同时共享数据是坏的。如果您有实例方法,但他们没有什么变异,你的罚款。

There's no particular effect on concurrency. The same rules are true: mutating shared data concurrently is bad. If you have instance methods but they don't mutate anything, you're fine.

有一个在一般设计的差异,虽然 - 静态方法应该总是是线程安全的(即你应该的的他们线程安全的),而实例方法一般不必须是(虽然你应记录类的多线程安全)。

There's a difference in general design though - static methods should almost always be thread-safe (i.e. you should make them thread-safe) whereas instance methods don't generally have to be (although you should document your class's thread-safety).

这篇关于净静态方法,它是对并发的影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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