action 线程问题。

2019-03-25 13:46|来源: 网路

比如现在有个Action,叫CZaction,有很多用户会访问这个action,这个action有对数据库操作,用线程Thread.sleep(1000);睡眠一秒才返回给用户。

我有这些疑问:1.如果很多用户访问这个action,睡眠线程会不会导致返回的action混乱?就是本来是返回给a的却返回给b了?
  2.如果不用mapping.findForward()到其他页面,用response.getWriter().print();它是否会返回给正确的访问者?就是一个访问者对应一个它自己的response.getWriter().print();???

相关问答

更多
  • 像这样的应该做的伎俩: private void ExecuteInBiggerStackThread(Action action, Helper h) { var operation = new ParameterizedThreadStart(obj => action((Helper)obj)); Thread bigStackThread = new Thread(operation, 1024 * 1024); bigStackThread.Start(h ...
  • 您的Index根本不使用任何异步功能。 你为什么把它标记为async ? 你一定是误解了什么,不知道是什么。 删除async Task规范。 Your Index does not make use of any async feature at all. Why did you mark it async? You must be misunderstanding something, not sure what. Remove the async Task specification.
  • 睡眠时间实际上是免费的。 在仪器中,查看“运行样本”而不是“所有样本”。 但这仍然不是一个理想的解决方案。 首先,你的睡眠时间很疯狂。 你真的需要0.1微米的粒度吗? 系统几乎肯定不会给你,因为处理器并不那么快。 我必须相信你可以将它提升到.1或.01。 但是,如果你可以提供帮助的话,这仍然是忙碌的等待,这并不理想。 更好的解决方案是使用NSCondition 。 在这个线程中,等待条件,并在处理线程中,当有空间写入时触发条件。 请注意命名。 不要使用前导大写字母命名方法(表示它是类名)。 并避免像这样直接 ...
  • 检查Parallel.ForEach,如下所示 static void Main(string[] args) { List p = new List() { "Test", "Test2", "Test3"}; Parallel.ForEach(p, Test); } public static void Test(string test) { Debug.WriteLine(test ...
  • 我会说你需要使用Control.Invoke来解决这个问题: 请参阅http://msdn.microsoft.com/library/system.windows.forms.control.invoke(v=vs.110).aspx I would say that you need to use Control.Invoke to solve that problem: See http://msdn.microsoft.com/library/system.windows.forms.control ...
  • 你不能。 听起来你大大超过了游泳池。 也许考虑一个受限制的队列/自定义线程池(即同步的生产者/消费者队列)? (不要增加池大小;这几乎总是错误的方法) You can't. It sounds like you are vastly over-using the pool. Perhaps consider a throttled queue / custom thread pool (i.e. a synchronized producer/consumer queue)? (don't increase ...
  • BeginInvoke会将您的任务排队到ThreadPool。 您无法控制标准.NET ThreadPool的调度。 您只能在代码实际执行后控制线程。 警告:更改ThreadPool线程的优先级被认为是危险的。 进一步阅读: .NET:为什么不改变ThreadPool(或任务)线程的优先级? 如果你能解释一下你想要实现的目标,也许你可以得到更好的解决方案? BeginInvoke will queue your task to the ThreadPool. You have no control over ...
  • 一,确保myObject.enable变量声明为volatile 。 二,我建议你使用java.util.concurrent包来模拟你...可能是一个信号量可以帮你... import java.util.concurrent.Semaphore; public class Example { public static void main(String[] args) throws InterruptedException { MyRunnable target = new MyRunn ...
  • 一种非便携式解决方案 bool getUserInput(string &result, Time deadline) // pick a timer, any timer { while(deadline > Time::now()) // assuming your timer has a now function { if(kbhit()) // THIS IS NOT PORTABLE. On windows it's called _kbhit() { c ...
  • 语法是: Invoke(action, "long1"); 委托是第一个参数,您要传递给它的参数如下。 The syntax would be: Invoke(action, "long1"); The delegate is the first parameter, and the argument(s) you want to pass to it follow.