java 创建静态方法,JAVA中的静态方法是创建单个实例吗?

I have a doubt.

Suppose in a multithreaded environment 10K users are using a site simultaniously and the site has a static method.

If a static method in JAVA creates a single instance, then the 10k-th user needs to wait for the method until rest of the users complete their usage.

Am I right?

Can anybody please explain?

解决方案

If a static method in JAVA create a single instance, then 10K th user need to wait for the method untill rest of the usres complete there usage.

Calling a static method doesn't create an instance implicitly. You can do so within the method, of course - but you don't have to.

Nor does creating an instance require a lock - although again, you can add synchronization should you wish to.

So in the case of a simple static method which doesn't need any synchronized access to shared data, there should be no problem with multiple threads calling that method concurrently.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值