常量和线程安全 [英] Constants and thread safety

查看:97
本文介绍了常量和线程安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的DAL中的所有类都是静态的,常量定义了

存储过程和参数。我在网站上遇到了一些问题,这让我想知道是否存在线程安全问题。


consts线程是否安全?以下示例是否会创建任何线程

安全问题?你会建议使用静态只读成员

而不是常量吗?


公共静态类测试

{

private const string TEST_ME =" test";


public static void DoSomething()

{

AnotherStaticClass.DoSomethingElse (TEST_ME);

}

}


谢谢,


Paul

Hi all,

All of the classes in my DAL are static, with constants defining the
stored procedures and parameters. I''ve been having some problems with
my site which makes me wonder if there''s a thread safety issue.

Are consts thread safe? Would the following example create any thread
safety issues? Would you recommend using static readonly members
instead of constants?

public static class Test
{
private const string TEST_ME = "test";

public static void DoSomething()
{
AnotherStaticClass.DoSomethingElse(TEST_ME);
}
}

Thanks,

Paul

推荐答案

我首先解释一下我遇到的具体问题。我不知道它是怎么回事
可能是一个问题因为它们只是读取值而且很可能

隐含式静态因为常量总是提供相同的值而不管

实例。 IMO您遇到的问题是由其他原因造成的......


---

Patrice

" Paul" < pa ********* @gmail.comaécritdansle message de news:
11 ********************* @ b75g2000hsg.googlegroups.c om ...
I would start by explaining the specific issue I had. I don''t see how it
could be a problem as they are read only values anyway and likely
implicitely static as a constant always provide the same value regardless of
the instance. IMO the problem you have is caused by something else...

---
Patrice
"Paul" <pa*********@gmail.coma écrit dans le message de news:
11*********************@b75g2000hsg.googlegroups.c om...

大家好,


我的DAL中的所有类都是静态的,常量定义为

存储过程和参数。我在网站上遇到了一些问题,这让我想知道是否存在线程安全问题。


consts线程是否安全?以下示例是否会创建任何线程

安全问题?你会建议使用静态只读成员

而不是常量吗?


公共静态类测试

{

private const string TEST_ME =" test";


public static void DoSomething()

{

AnotherStaticClass.DoSomethingElse (TEST_ME);

}

}


谢谢,


Paul
Hi all,

All of the classes in my DAL are static, with constants defining the
stored procedures and parameters. I''ve been having some problems with
my site which makes me wonder if there''s a thread safety issue.

Are consts thread safe? Would the following example create any thread
safety issues? Would you recommend using static readonly members
instead of constants?

public static class Test
{
private const string TEST_ME = "test";

public static void DoSomething()
{
AnotherStaticClass.DoSomethingElse(TEST_ME);
}
}

Thanks,

Paul



您好Patrice,


我有缓冲区溢出/溢出类型问题其中,当我的网站忙于
忙时,响应输出偶尔会包含来自完全不同页面的不同并发请求的输出

。这个

打破当前请求的HTML并可能暴露其他

人的信息。


谢谢,

Paul


4月11日上午11:54,Patrice < http://www.chez.com/scribe/wrote:
Hi Patrice,

I''m having a buffer overrun/overflow-type issue where, when my site is
busy, the response output occasionally contains the output of
different, concurrent requests, from completely different pages. This
breaks the HTML for the current request and potentially exposes other
peoples'' information.

Thanks,

Paul

On Apr 11, 11:54 am, "Patrice" <http://www.chez.com/scribe/wrote:

我将首先解释我遇到的具体问题。我不知道怎么回事
可能是一个问题,因为他们无论如何都是只读值而且很可能

隐含的静态因为常量总是提供相同的值而不管

实例。 IMO您遇到的问题是由其他原因造成的......


---

Patrice


" ;保罗" < paul.hes ... @gmail.comaécritdansle message de news:

1176306349.881922.89 ... @ b75g2000hsg.googlegroups.c om ...
I would start by explaining the specific issue I had. I don''t see how it
could be a problem as they are read only values anyway and likely
implicitely static as a constant always provide the same value regardlessof
the instance. IMO the problem you have is caused by something else...

---
Patrice

"Paul" <paul.hes...@gmail.coma écrit dans le message de news:
1176306349.881922.89...@b75g2000hsg.googlegroups.c om...

大家好,
Hi all,


我的DAL中的所有类都是静态的,常量定义了

存储过程和参数。我在网站上遇到了一些问题,这让我想知道是否存在线程安全问题。
All of the classes in my DAL are static, with constants defining the
stored procedures and parameters. I''ve been having some problems with
my site which makes me wonder if there''s a thread safety issue.


consts线程是否安全?以下示例是否会创建任何线程

安全问题?你会建议使用静态只读成员

而不是常量吗?
Are consts thread safe? Would the following example create any thread
safety issues? Would you recommend using static readonly members
instead of constants?


public static class Test

{

private const string TEST_ME =" test" ;
public static class Test
{
private const string TEST_ME = "test";


public static void DoSomething()

{

AnotherStaticClass.DoSomethingElse(TEST_ME);

}

}
public static void DoSomething()
{
AnotherStaticClass.DoSomethingElse(TEST_ME);
}
}


谢谢,
Thanks,


Paul-隐藏引用文字 -
Paul- Hide quoted text -



- 显示引用文字 -


- Show quoted text -



你的DAL究竟是什么静态的?如果你有静态读/写成员

(方法调用如果他们使用本地数据不应该是一个问题)请记住

这意味着这个值是整个应用程序都是一样的,并且

ASP.NET是一个单独的应用程序。这是你设置的静态值

某个地方是所有用户都可以使用的......

Paul < pa ********* @gmail.comaécritdansle message de news:
11 ******** @ p77g2000hsh.googlegroups。 com ...

嗨帕特里斯,


我有一个缓冲区溢出/溢出类型的问题,当我的网站是

忙,响应输出偶尔包含来自完全不同页面的不同并发请求的输出

。这个

打破当前请求的HTML并可能暴露其他

人的信息。


谢谢,

Paul


4月11日上午11:54,Patrice < http://www.chez.com/scribe/wrote:
What exactly is static in your DAL ? If you have static read/write members
(method calls shouldn''t be a problem if they use local data) keep in mind
that it means that this value is the same for the whole application and that
ASP.NET is a single application. That is the static value you''ll set
somewhere is the one that will be available to all users...
"Paul" <pa*********@gmail.coma écrit dans le message de news:
11**********************@p77g2000hsh.googlegroups. com...
Hi Patrice,

I''m having a buffer overrun/overflow-type issue where, when my site is
busy, the response output occasionally contains the output of
different, concurrent requests, from completely different pages. This
breaks the HTML for the current request and potentially exposes other
peoples'' information.

Thanks,

Paul

On Apr 11, 11:54 am, "Patrice" <http://www.chez.com/scribe/wrote:

我将首先解释我遇到的具体问题。我不知道它是怎么回事
可能是一个问题,因为它们只是读取值而且很可能

隐含静态,因为常量总是提供相同的值,无论



实例。 IMO您遇到的问题是由其他原因造成的......


---

Patrice


" ;保罗" < paul.hes ... @gmail.comaécritdansle message de news:

1176306349.881922.89 ... @ b75g2000hsg.googlegroups.c om ...
I would start by explaining the specific issue I had. I don''t see how it
could be a problem as they are read only values anyway and likely
implicitely static as a constant always provide the same value regardless
of
the instance. IMO the problem you have is caused by something else...

---
Patrice

"Paul" <paul.hes...@gmail.coma écrit dans le message de news:
1176306349.881922.89...@b75g2000hsg.googlegroups.c om...

大家好,
Hi all,


我的DAL中的所有类都是静态的,常量定义了

存储过程和参数。我在网站上遇到了一些问题,这让我想知道是否存在线程安全问题。
All of the classes in my DAL are static, with constants defining the
stored procedures and parameters. I''ve been having some problems with
my site which makes me wonder if there''s a thread safety issue.


consts线程是否安全?以下示例是否会创建任何线程

安全问题?你会建议使用静态只读成员

而不是常量吗?
Are consts thread safe? Would the following example create any thread
safety issues? Would you recommend using static readonly members
instead of constants?


public static class Test

{

private const string TEST_ME =" test" ;
public static class Test
{
private const string TEST_ME = "test";


public static void DoSomething()

{

AnotherStaticClass.DoSomethingElse(TEST_ME);

}

}
public static void DoSomething()
{
AnotherStaticClass.DoSomethingElse(TEST_ME);
}
}


谢谢,
Thanks,


Paul-隐藏引用文字 -
Paul- Hide quoted text -



- 显示引用文字 -


- Show quoted text -






这篇关于常量和线程安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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