Site Search :
Standard Enterprise XML Methodology Pattern Setting Tunning Other
Article Contributors
GuestBook
Javapattern Maven
XSourceGen Dev
JetSpeed Test
JLook Image
jLook Family Site


Multiprocess JVM Implemetation
 
Java¸¦ ÀÌ¿ëÇØ ServerApplicationÀ» ±¸ÇöÇÒ ¶§ ±âº»ÀÌ µÉ ¼ö ÀÖ´Â Multiprocess JVMÀ» ±¸ÇöÇϱâ À§ÇÑ ±âº» Áö½ÄÀ» ½ÀµæÇغ¸°íÀÚ ÇÕ´Ï´Ù. ÀÌÁ¦ ¿ì¸®´Â ÇϳªÀÇ JVM¿¡¼­ ´Ù¼öÀÇ Process¸¦ »ý¼ºÇÏ°í °ü¸®ÇÒ ¼ö ÀÖ°Ô µË´Ï´Ù. ( 2003/02/28 ) 154
Written by runjava - ±èÀçȯ
1 of 2
 
Á¦¸ñ : Multiprocess JVM ±¸ÇöÇϱâ (1)

1. °³¿ä
JVMÀÌ ·Îµå µÉ¶§ ¸¹Àº ½Ã½ºÅÛ ¸Þ¸ð¸®¸¦ Â÷ÁöÇÕ´Ï´Ù. ±×¸®°í, ÀϹÝÀûÀÎ °æ¿ì¿¡ ÇϳªÀÇ JVM¿¡¼­´Â ÇϳªÀÇ ÇÁ·Î¼¼½º°¡ ÀÛµ¿ÇÏÁÒ. ±×·¸´Ù¸é ½Ã½ºÅÛ¿¡¼­ ¿©·¯ °³ÀÇ ÀÚ¹Ù ¾ÖÇø®ÄÉÀ̼ÇÀ» ½ÇÇàÇÑ´Ù¸é ¸Þ¸ð¸®¿¡ ´ëÇÑ ³¶ºñ°¡ Ä¿Áú °ÍÀ̶ó´Â °ÍÀº ÃæºÐÈ÷ ÁüÀÛÀÌ µÇ´Â ÀÏÀÌ°ÚÁö¿ä? ´ëºÎºÐÀÇ ÀÚ¹Ù °³¹ßÀÚµéÀÌ ¿£ÅÍÇÁ¶óÀÌÁî ȯ°æ¿¡¼­ »ç¿ëµÉ ½Ã½ºÅÛÀ» °³¹ßÇÑ´Ù°í ÇßÀ» ¶§ ÀÌ°ÍÀº Á¤¸» Áß¿äÇÑ ¹®Á¦°¡ µÉ ¼ö ÀÖ½À´Ï´Ù.
±×·¸´Ù¸é ÇØ°á ¹æ¹ýÀÌ ¾øÀ»±î? ±×³É JVM Çϳª¿¡¼­ ¿©·¯ °³ÀÇ ÇÁ·Î¼¼½º¸¦ µ¹¾Æ°¡µµ·Ï ÇÏ¸é µÇ°ÚÁÒ. ÇÏÁö¸¸, ´Ü¼øÈ÷ java ¸í·ÉÀ» ŸÀÌÇÎ ÇÏ´Â °ÍÀ¸·Î´Â ÀÌ°ÍÀ» ÇØ°áÇÒ ¼ö ¾ø½À´Ï´Ù. ¶§¹®¿¡ ÀÌ Article¿¡¼­´Â °£´ÜÇÏ°Ô³ª¸¶ JVM¿¡¼­ ´Ù¼öÀÇ ÇÁ·Î¼¼½º¸¦ µ¹¸± ¼ö ÀÖµµ·Ï ±¸ÇöÇØ º¸°íÀÚ ÇÕ´Ï´Ù.
ÀÚ! ¼Ò½ººÎÅÍ ¹ÞÀ¸½Ã±¸¿ä. Çϳª¾¿ Â÷·Ê´ë·Î »ìÆ캸µµ·Ï ÇÏÁÒ..

2. ³»¿ë
  Multiprocess JVMÀ» ±¸ÇöÇϱâ À§ÇØ Ã³¸®ÇØ¾ß ÇÒ ¹®Á¦¿¡´Â ¾î¶² °ÍµéÀÌ ÀÖÀ»±î¿ä?

** ¿ä±¸ Á¶°Ç **
1) main()À» °¡Áö°í Àִ Ŭ·¡½º¸¦ ¸Þ¸ð¸®·Î ÀÐ¾î µéÀÌ°í main()À» ½ÇÇàÇÒ ¼ö ÀÖ¾î¾ß ÇÕ´Ï´Ù.

// ProcessManager.java

public static void startProcess ( String classname, String[] args)
throws Exception {

   // Ŭ·¡½º¸¦ ¸Þ¸ð¸®·Î ÀоîµéÀÔ´Ï´Ù.
  Class classObject = Class.forName(classname);

  // ³Ñ°Ü¹ÞÀº String[]ÀÇ Argument·Î ºÎÅÍ Å¸ÀÔ°´Ã¼¸¦ ¾ò¾î³À´Ï´Ù.
  Class[] paramType = {args.getClass() };
  // main()¿¡ ´ëÇÑ Reference¸¦ ¾ò¾î³À´Ï´Ù.
  Method main = classObject.getMethod("main", paramType);
  Object[] mainParams = {args};
  // main()À» ½ÇÇàÇÕ´Ï´Ù.
  main.invoke (null, mainParams);
}

À§ÀÇ ¸Þ¼Òµå¸¦ ÀÌ¿ëÇØ ¿©·¯ °³ÀÇ ¾ÖÇø®ÄÉÀ̼ÇÀ» ½ÇÇà½ÃÄѺ¸½Ã¸é ½Ç¸ÁÇÏ½Ç °Ì´Ï´Ù. ¿Ö³ÄÇÏ¸é ¾ÖÇø®ÄÉÀ̼ǵéÀÌ ¼øÂ÷ÀûÀ¸·Î ½ÇÇàµÇ±â ¶§¹®ÀÌÁÒ. ¸ÕÀú ½ÇÇà½ÃŲ °ÍÀÌ Á¾·áÇؾ߸¸ ´ÙÀ½ °ÍÀÌ ½ÇÇàÀ» ÇÏ°Ô µË´Ï´Ù. ÀÌ·¡¼­¾ß ¿ÏÀüÇÑ Multiprocess ¶ó°í ÇÒ ¼ö ¾ø°ÚÁÒ?

 

2) °¢°¢ÀÇ ÇÁ·Î¼¼½ºµéÀº µ¶¸³ÀûÀÎ Thread·Î µ¿À۵Ǿî¾ß ÇÕ´Ï´Ù.
(¿©±â¿¡¼­ Process¿¡ ´ëÇÑ Á¤º¸¸¦ ´ã°í ÀÖ´Â ProcessWrapper.java °¡ ÇÊ¿äÇÏ°Ô µË´Ï´Ù. ¼Ò½º¸¦ ÂüÁ¶Çϼ¼¿ä!)

// ProcessManager.java
public static ProcessWrapper startAnotherClass (String classname, String[] args) {
  ProcessWrapper process = new Process(classname, args);
  // ¸Å ÇÁ·Î¼¼½º¸¦ Thread·Î ½ÇÇà½ÃŲ´Ù.
  Thread thread = new Thread(process);
  thread.start();
  return process;
}

 


3) °¢°¢ÀÇ ÇÁ·Î¼¼½º¸¦ °³º°ÀûÀ¸·Î Á¤Áö½Ãų ¼ö ÀÖ¾î¾ß ÇÕ´Ï´Ù.
ÀÌ ¹®Á¦´Â ProcessWrapper.java¿¡¼­ MainThread¿¡ ´ëÇÑ Reference¸¦ º¸Á¸ÇÏ°í ÀÖ´Ù°¡ stop()À» ÀÌ¿ëÇØ ÁßÁö ½ÃÅ°´Â ¹æ¹ýÀ¸·Î 󸮸¦ ÇÕ´Ï´Ù.

 
1 2
References
 
1) O'REILY NETWORK : Multiprocess JVMs 2001/09/25
2) The Java Language Specification : Chapter 17 Threads and Locks 3) This article Source : jvm_process_src.zip
Copyright ¨Ï 2003 www.javapattern.info & www.jlook.com, an jLOOK co.,LTD