×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

Just answer part of your questions

1) You know how to create a Thread using the Thread class.

2) A Java application itself is a Process on your native machine.

3) JVM can initiate a new (native) Process. The code is as follows

Process p = Runtime.exec(".....");

4) The title of your response is full of confusion. Let me cite it here--- How can I judge a running program is Process or Thread. The reason is that a running programm cannot be simply a Thread.

5) Whenever you talk about a Thread, please remember it means " a thread of control".

6) If you are really interested in hacking on the precise definitions, I suggest you pick up a book on Operating System. I guess you have one. As you browse the book, please pay attention to another term---task. Usually, people do a task in a seperate Thread.

7) Good luck.
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / What's the difference between Thread and Process? It's said process is expensive and thread is much more efficient when I learn the difference between CGI and Servlet. tks.
    • a process can have one or n threads
      • I can't get any idea.
        • I doubt if you have Java textbooks ;-):-);
          Let me give an example.

          An OS can have a bunch of processes, for instance, MS Word, Netscape Navaigator. Your Java Application is one process.
          A thread means a thread of control IN A PROCESS. In a process,
          they are usually sevaral threads. Take MS Word as an example.
          After you begin MS Word process, it has at least one thread handling your keyboard input, one thread handling spelling error, one thread handing auto complete. Wht I am talking may not be technically precise, but it can give you an idea that we are talking about threads in a process. In another word, guest's answer is absolutely right, albeit a little bit simple.
          • Sorry. The question is still here. How can I judge a running program is Process or Thread. If not Jabber tell me, how can I know MS Word is process, comparing with keyboard input, spelling error are threads?
            Sorry, I need a essence difference instead surface difference.

            I know that Servlet is running as a thread and CGI often in a process. If not the textbook tell me such thing, how can I know CGI is running in process and Servlet is running in thread?

            More concretely, how do we create a process or a thread using Java? If Java can't, what language can? I know you begin a new program often begin a new process. But why? There must be something under the surface.

            tks.
            • Just answer part of your questions
              1) You know how to create a Thread using the Thread class.

              2) A Java application itself is a Process on your native machine.

              3) JVM can initiate a new (native) Process. The code is as follows

              Process p = Runtime.exec(".....");

              4) The title of your response is full of confusion. Let me cite it here--- How can I judge a running program is Process or Thread. The reason is that a running programm cannot be simply a Thread.

              5) Whenever you talk about a Thread, please remember it means " a thread of control".

              6) If you are really interested in hacking on the precise definitions, I suggest you pick up a book on Operating System. I guess you have one. As you browse the book, please pay attention to another term---task. Usually, people do a task in a seperate Thread.

              7) Good luck.
              • thank you!
                • Try to make it clear
                  本文发表在 rolia.net 枫下论坛The timing of a central processor can be into time slices. in every time slice a certain task(a small piece of program code) will be allowed to do according to the scheduler of the OS. Because the time slice is very small, from user's view, many applications can be excuted at the same time. That 's called multi tasking. UNIX and windows are samples of multi task systems but DOS is not. a process is a piece of programs which can be in the form of DLL, service or EXE on the windows platform. every process is defaultly a thread, which is called primary thread. Besides the primary thread , a process can create other threads as needed. A process with more than one thread is called multi-thread process. threads can communicate with each other both in-processly(threads within a process) and out-processly(threads between processes).

                  the concept of the thread is almost platform independant, although there are differences in the implementations between unix and windows.JAVA and C++ have their own librarys of threads. But they share almost the same concept.

                  To expand a little, any modern computer languages are nothing but tools to make runnable programs. Languages themselves can be devided into object oriented(C++, JAVA, smalltalk, or generally UML) and structure oriented(c, pascal,Fortran). EJB,CORBA,COM themselves are not parts of a language. They are the very thing to let people build the real applications easier. Actually most of the concepts beyond the language are implemented in the libararies to let programmers avoid coding from scrach.

                  So to be a programmer or a architect. knowledge beyond the language is more important than or at least the same as the language itself.更多精彩文章及讨论,请光临枫下论坛 rolia.net
                  • One more word
                    The implementations of Java Virtual Machines, roughly pseaking,
                    falls into two categories. One uses the native threads, another creates its green threads in itself.

                    Actually, it is very easy to make people understand what a process is. But
                    many senior programmer, even though they have 20 years expereinces, cannot do robust Multithreading programming. If one want's to do robust Java programming, he/she at least read one of the following books:
                    1) Java Threads from Oreilley; 2) Taming Java Threads. Without good understanding, people can easily get into the following problem: deadlock and CPU startvation. Task scheduling is by no means an easy topic we can clarify during the discussion here.