'thread'에 해당되는 글 2건

  1. 2013.04.08 [java] junit thread testing.
  2. 2010.01.07 Process vs Thread

[java] junit thread testing.

ITWeb/개발일반 2013.04.08 12:51

메인 class 에 multi thread 로 구현된 코드를 junit test 로 테스트 할려고 할때 복잡 하지 않고 단순 테스트용 도로만 그냥 돌리고 싶다면 test code 에 sleep(적당한 시간) 을 주면 테스트 가능 합니다.


그냥 돌리게 되면 test 수행이 끝남과 동시에 thread 는 종료가 되어서 실제 thread 내부 코드가 잘 동작 하는지 확인이 안됩니다.


아래는 그냥 테스트 한 코드이니 참고 정도만 하세요.


@Test

public void testClientIndexer() throws Exception {

    ClientIndexer clientIndexer ;


    clientIndexer = new ClientIndexer();

    clientIndexer.connect();

    clientIndexer.open();


    Thread.sleep(30000);

}


신고

'ITWeb > 개발일반' 카테고리의 다른 글

[Maven] pom.xml <scope> 설명.  (0) 2013.05.03
[java] java.util.concurrent.* 링크  (0) 2013.04.09
[java] junit thread testing.  (0) 2013.04.08
[java] read properties or xml file.  (0) 2013.04.05
java system properties...  (0) 2013.04.05
vim에서 개행문자 삽입하기.  (0) 2013.04.03
tags : junit, test, thread
Trackback 0 : Comment 0

Process vs Thread

스크랩일반 2010.01.07 18:28

원문보기 : http://en.wikipedia.org/wiki/Process_(computing)
원문보기 :
http://en.wikipedia.org/wiki/Thread_(computer_science)


Process

In computing, a process is an instance of a computer program, consisting of one or more threads, that is being sequentially executed[1] by a computer system that has the ability to run several computer programs concurrently.

A computer program itself is just a passive collection of instructions, while a process is the actual execution of those instructions. Several processes may be associated with the same program; for example, opening up several instances of the same program often means more than one process is being executed. In the computing world, processes are formally defined by the operating system (OS) running them and so may differ in detail from one OS to another.

A single computer processor executes one or more (multiple) instructions at a time (per clock cycle), one after the other (this is a simplification; for the full story, see superscalar CPU architecture). To allow users to run several programs at once (e.g., so that processor time is not wasted waiting for input from a resource), single-processor computer systems can perform time-sharing. Time-sharing allows processes to switch between being executed and waiting (to continue) to be executed. In most cases this is done very rapidly, providing the illusion that several processes are executing 'at once'. (This is known as concurrency or multiprogramming.) Using more than one physical processor on a computer, permits true simultaneous execution of more than one stream of instructions from different processes, but time-sharing is still typically used to allow more than one process to run at a time. (Concurrency is the term generally used to refer to several independent processes sharing a single processor; simultaneously is used to refer to several processes, each with their own processor.) Different processes may share the same set of instructions in memory (to save storage), but this is not known to any one process. Each execution of the same set of instructions is known as an instance— a completely separate instantiation of the program.

For security and reliability reasons most modern operating systems prevent direct communication between 'independent' processes, providing strictly mediated and controlled inter-process communication functionality.



Thread

In computer science, a thread of execution results from a fork of a computer program into two or more concurrently running tasks. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process. Multiple threads can exist within the same process and share resources such as memory, while different processes do not share these resources.

On a single processor, multithreading generally occurs by time-division multiplexing (as in multitasking): the processor switches between different threads. This context switching generally happens frequently enough that the user perceives the threads or tasks as running at the same time. On a multiprocessor or multi-core system, the threads or tasks will generally run at the same time, with each processor or core running a particular thread or task. Support for threads in programming languages varies. A number of languages support multiple threads but do not allow them to execute at the same time. Examples of such languages include Python (at least the C version, also known as CPython, but not IronPython or Jython), and OCaml, because the parallel support of their runtime environment is based on a central lock, called the "Global Interpreter Lock" in Python and the "master lock" in Ocaml. Other languages may be limited because they use threads that are user threads, which are not visible to the kernel, and thus cannot be scheduled to run concurrently. On the other hand, kernel threads, which are visible to the kernel, can run concurrently.

Many modern operating systems directly support both time-sliced and multiprocessor threading with a process scheduler. The kernel of an operating system allows programmers to manipulate threads via the system call interface. Some implementations are called a kernel thread, whereas a lightweight process (LWP) is a specific type of kernel thread that shares the same state and information.

Programs can have user-space threads when threading with timers, signals, or other methods to interrupt their own execution, performing a sort of ad-hoc time-slicing.

신고

'스크랩일반' 카테고리의 다른 글

네이버 체크아웃  (0) 2010.07.02
[펌]생산성 높은 소프트웨어 개발  (0) 2010.01.21
Process vs Thread  (0) 2010.01.07
[GM대우]라세티 프리미어 ㅎㅎ  (3) 2009.11.16
eclipse + maven plugin 설치  (0) 2009.11.09
[펌]Software architecture  (0) 2009.10.19
Trackback 0 : Comment 0