Sometimes it is perfectly sensible to spawn a new thread for each new task.
有时,为每个新任务生成一个新线程是十分明智的。
While a thread is running, either uploading or downloading, you can query it to check on its status to provide the user with feedback (e.g. a progress bar).
当一个线程在运行的时候,不管是上传还是下载,你可以查询进程状态并且给用户一个反馈(例如一个进度条)。
A general solution for the problem above is to have each user thread hold a locale variable by passing the variable to the user thread during its construction.
对于以上问题通用的解决方法,是通过在构造变量期间将其传递给用户线程,来让每一个用户都有一个场所变量。
As mentioned above, sometimes it is perfectly sensible to spawn a new thread for each new task.
如同上面所提到的,有时,为每个新任务生成一个新线程是十分明智的。
A thread is created to handle each new user connection.
一个线程被创建来处理每个新用户连接。
A significant risk in all kinds of thread pools is thread leakage, which occurs when a thread is removed from the pool to perform a task, but is not returned to the pool when the task completes.
各种类型的线程池中一个严重的风险是线程泄漏,当从池中除去一个线程以执行一项任务,而在任务完成后该线程却没有返回池时,会发生这种情况。
A simple approach to this is to just generate a random number when a thread is spawned and prepend that number to all output lines.
为此,一种简单的方法就是仅在派生某个线程时才生成一个随机数,并将该随机数追加到所有输出行上。
A better approach is to start a timer, and have timer poke the event thread every so often to go look at the staging area for updates.
更好的方法是启动计时器,并且使计时器不时地提醒事件线程去查看中间区域,以寻找更新。
One (theoretical) way is to configure a separate thread per mailbox.
一种(理论上的)方法是单独为每个邮箱配置一个线程。
Usually, the main use of a semaphore is to synchronize a thread?s action with other threads.
通常,信号的主要用途是同步某个线程与其他线程的动作。
The solution, again, is to run everything from a different thread.
此外,解决方案是在另一个不同线程上运行每一件事情。
The message listener service is configured to use a thread pool that has the maximum threads property set to 4.
消息侦听器服务配置为使用最大线程属性设置为4的线程池。
The interrupted status is initially false; when a thread is interrupted by some other thread through a call to Thread.interrupt(), one of two things happens.
中断状态初始时为 false;当另一个线程通过调用 Thread.interrupt() 中断一个线程时,会出现以下两种情况之一。
The code within each thread is sent to a remote machine to be executed.
每个线程内的代码都被发送到一台远程计算机去执行。
A single arrow indicates a thread contention: One thread is waiting for another thread to release a lock.
一支单独的箭头指出一个线程竞争:一个线程正在等候另一个线程释放一个锁。
Each routine represents a separate "thread of execution" and is referred to as a task.
每一个程序表现得像分开的“执行的线程”并且被看作是一个任务。
However, because there is only one AWT thread, it is undesirable to execute tasks in the AWT thread that may take a perceptible amount of time to complete.
然而,由于只有一个AWT线程,因此要在AWT线程中执行任务可能要花费相当长时间才能完成,这是不可取的。
A thread is allocated to handle shutdown events.
一个线程被分配为处理关机事件。
This is the function that is invoked whenever a message is sent to the thread.
它就是每当消息被发送给线程时就会调用的函数。
Because some processing can take a long time, we need multiple processing threads per production line to make sure that a thread is always available to work on the latest measurement.
由于某些处理可能要占用较长的时间,因而需要为每条生产线使用多个处理线程,确保总有一个线程能来处理最新的度量结果。
When one thread is executing a synchronized block, any thread waiting to enter that block is stalled.
当一个线程正在执行一个同步块时,任何等待进入该块的线程都将被阻塞。
Instead, interruption is a way of politely asking another thread to stop what it is doing if it wants to, at its convenience.
相反,中断是礼貌地请求另一个线程在它愿意并且方便的时候停止它正在做的事情。
'There is a variegated thread that goes purple to white then back to purple,' he said.
“有一种杂色线,它的颜色从紫色变成白色,然后又变回紫色”,他说。
They all output the same value illustrating that this is a thread-safe generic way to create singletons.
所有线程都返回相同的值,这说明这是一个线程安全的使用泛型来实现的单态模式。
What you really need is a way to put a thread to sleep while it waits for some condition to be met.
真正需要的是这样一种方法,当线程在等待满足某些条件时使线程进入睡眠状态。
However, to avoid potentially severe thread starvation between applications, it is possible to configure a thread pool to allow thread allocation beyond maximum thread size.
不过,为避免应用程序之间发生严重的线程供给不足问题,可以配置一个线程池,允许线程的分配超出最大线程大小。
Each connection that is made will try to begin a message flow thread.
发出的每个连接都将尝试开始一个消息流线程。
Another possibility is to fork a separate low-priority thread during startup to perform initialization when the system is idle, although this choice requires more care to handle synchronization.
还有一种可能是在启动时派生一个单独的低优先级的线程,当系统空闲时再去完成初始化,不过这种方法需要特别注意处理好同步。
A Runnable is submitted to a custom thread pool.
将可运行线程提交到自定义线程池。
In a multiprocessing environment, the processing time for a thread is related to the availability of system resources and synchronization with other threads.
在多处理环境中,线程的处理时间与可用系统资源以及与其他线程的同步有关。
应用推荐