Java 소개 2003.1.21 강사 : 이욱준 차장(MCSC).

Similar presentations


Presentation on theme: "Java 소개 2003.1.21 강사 : 이욱준 차장(MCSC)."— Presentation transcript:

1 Java 소개 강사 : 이욱준 차장(MCSC)

2 목차 J2SE Java 2 SDK 1.4 소개 HP Java Tool JVM J2EE

3 Java 2 SDK, Standard Edition
Tools Java Virtual Machine Java APIs Java Implementation + Native Libraries

4 Java software development kit (SDK)
Java Compiler (javac) Java Debugger (jdb) Additional Tools sql beans naming lang swing io awt security applet sound math text util net rmi corba accessibility Java Virtual Machine Java Plug-in

5 Java Runtime Environment (JRE)
sql beans naming lang swing io awt security applet sound math text util net rmi corba accessibility Java Virtual Machine Java Plug-in JRE

6 enterprise Java roadmap
Time-to-market Sun Theme 1.4 64 bit 1.4.1 Itanium 1.5 RAS, Scalability HP-UX / IPF 1.3.1 PA sync HotSpot JVM Competitive with IPF, lags RISC 1.4.1 PA sync 32 & 64 bit IPv6 PA-RISC synch 1.5 JavaSoft sync 32 & 64 bit Scalability The Java with Hotspot technology was officially released in October 99. At the 2000 JavaOne conference, leadership benchmark numbers were released for the SPECjvm98 and SPECjbb2000. These specific benchmarks measure JVM and server-side performance. This was repeated at the 2001 JavaOne conference where yet another industry leading SPECjvm98 result was announced. An early access release of Java was made in June A full production release of the product is planned in August of this year. PA 1.4 (32-bit & 64-bit) is target for 1st quarter of 2002. HP-UX 11.0 & 11i PA 1.4 JavaSoft sync 32 & 64 bit IPv6 1.4.1 JavaSoft sync 32 & 64 bit 1.5 JavaSoft sync 32 & 64 bit Scalability 4Q01 1Q02 2Q02 3Q02 4Q02 1Q03 2Q03 3Q03

7 Java 2 SDK 1.4 소개 새로운 Java 2 의 주요 기능 성능 64 bit 지원 장애 지원
Version 1.3 was released in November 2000 and includes significant performance and functionality enhancements. For this release,we’ve included our proven HotSpot as the default VM. . Additional features in 1.3 include: - Java IDL. Defining IDL interfaces in Java (CORBA-like) available - JNDI. JNDI naming service available in this release. - RMI-IIOP. Support to allow RMI applications to run over the IIOP protocol We are also in the process of producing a HotSpot 2.0 JVM, optimized for server-side applications, with a –clientapp for client applications (faster startup, less memory usage). Additional information: Customer stories: Aruba ‘s buyer product works on hp-ux with 1.3. Ariba is the world's largest business-to-business commerce network for operating resources over the Internet. Ariba, Inc. provides eCommerce solutions for all strategic segments of business-to-business eCommerce, including buyers, suppliers, value-added service providers, and Net market makers. Spincircuit’s collaboration web site is enabled via e-speak and Java 2. SpinCircuit, Inc. bridges the gap between electronics designers and the supply chain network with a new Internet gateway, which provides information e-services throughout the electronics supply chain. By linking printed circuit assembly (PCA) design engineers’ desktops directly to component suppliers and other key supply chain participants, SpinCircuit provides critical information to bring design into much closer collaboration with manufacturing. HP’s Java-based e-speak software platform provides the intelligent interaction for the e-services that work together to create this unique solution. ATG’s Dynamo: The Dynamo product suite is the first complete solution designed specifically to create a platform for performing Internet Customer Relationship Management [ICRM]. ICRM is the essential practice of establishing and maintaining profitable, long-term relationships with customers on the Internet. The Dynamo Product Suite is a standards based scalable platform for developing and deploying ICRM applications. The Java-based Dynamo Product Suite is A proven, extensible platform with the capability to meet the challenges of ICRM. It is comprised of three major components: Dynamo Application Server, Dynamo Personalization Server, and Dynamo Commerce Server. Others: Documentum, Metriom HP/Agilent’s internal partners: Smart Internet Usage (SIU). SIU offers service providers the most manageable, extensible platform to manage network resources and introduce metered IP services more quickly in the emerging billion-node Internet. If a device or service logs its usage statistics, key SIU Java objects such as the Encapsulator and Parser can be extended to capture the data stream as a set of Normalized Metered Events FireHunter: Firehunter is entirely written in Java. Firehunter

8 Java 2: SDK 1.4 성능 및 기능 새로운 Java 2 의 주요 기능 XML unified printing API
JAXP XML Parsing (JAXP) 1.0 XML Processing (JAXP) 1.1 XML Data Binding unified printing API Preferences API Image I/O Framework Simple Assertion Facility Logging API

9 Java 2: SDK 1.4 성능 및 기능 새로운 Java 2 의 주요 기능 성능 Certification Path API
Network Launching Protocol & API JavaBean 그래프 Archiving 성능 Swing – Java 2D 및 Swing 성능 개선 리모트 디스플레이 class loading 시간의 단축 및 빠른 start-up 시간 빠른 GC 및 다른 종류의 GC 를 가능하게 하는 API 어플리케이션의 thread stack 크기 조정 기능

10 Java 2: SDK 1.4 성능 및 기능 64 bit 지원 장애 지원 라이브러리 JVM 향상된 에러 리포팅
native 코드에서 crash 발생시 symbolic 정보 제공 부분적인 thread 덤프 VM 상태 덤프 각 에러에 대한 고유 에러 메시지 제공

11 그 외의 Java API: Java plug-in
웹 브라우저에서 hp의 최신 Java 실행 Netscape Communicator에서 applet 을 실행할 경우 일관성 있고 안정적인 환경 제공 Netscape Communicator 4.7+에서 사용 가능 10.20 은 hp 의 Java 지원 11.0 은 hp 의 Java 2 지원 Java Plug-in for Netscape Navigator running on hp-ux provides consistency and reliability when running applets in your browser on hp-ux. What about Internet Explorer? IE does seem to run on HP-UX, but it is an unsupported product. What’s significant about this JPI is NSCP 6 will no longer provide a Java Plugin. Additional information Customer stories: PTC (Windchill) & Metaphase: uses Netscape and the JPI for displaying models for designer collaboration across the web

12 그 외의 Java API: Java 3D 사용의 용이 네트워크를 통해 3D 모델 및 데이터의 공유
프로그래밍의 단순화 (e.g. automatic rendering, collision detection, morphing...) 프로그램 개발 시간의 단축 네트워크를 통해 3D 모델 및 데이터의 공유 하드웨어 accelerator 를 이용한 최적의 성능 A performance-enhanced version of Java 3D that simplifies 3D-graphics programming and enables collaboration of 3D models and data over the internet. Java 3D for HP-UX delivers the fastest measured performance on any platform. Comes as a set of class files. UX delivers the fastest measured performance on any platform. Additional information Customer stories: SDRC: IDEAS viewer uses Java3d / Java 1.2 for efficient design and viewing of 3D models on workstations/PC. The I-DEAS Viewer is a comprehensive set of tools for interrogating models produced in I-DEAS 8. It has a simple and concise user interface, making interrogation of I-DEAS models quick and efficient. You don't need to know how to use I-DEAS to use the viewer Webscope: uses Java 3D 1.2 and JPI/Java 2. WebScope is the first secure, Web-native solution for product collaboration and communication via the Internet. One click in your browser puts you in real-time contact with your customers, suppliers and business partners -- wherever you are, on any network, on any platform. University of Wisconsin: VisAD uses Java 3D VisAD is a Java component library for interactive and collaborative visualization and analysis of numerical data. The name VisAD is an acronym for "Visualization for Algorithm Development".

13 IPF에서의 Java IA-64 의 공동 개발 및 그로 인한 해당 기술의 높은 이해 hp-ux, Linux, 및 Windows
PA-RISC 어플리케이션을 IPF에서 변경 없이 실행 runtime 바이너리 호환 hp-ux만의 기능 Itanium 을 지원하는 제품 Java SDK 1.3 HPjconfig 2.0 HP Apache HP co-invented EPIC and IA-64, we are the only vendor who truly understands this technology. Consequently, we have an advantage over all other vendors by being able to apply this insight to our hardware, software, and support solutions. HP customers have the flexibility to select between hp-ux, Linux, or WIN64 as their operating system on IA-64. HP9000 Itanium servers, however, will lead with hp-ux. HP has signed up over 500 partners to help them port their applications that run under the 64-bit implementations of hp-ux, WIN64, and Linux on IA ISVs who have signed up for our (Designing the Future) premier partner program get access to Itanium servers, HP’s technical consulting and training, and the latest HP and other development tools for the IA-64 environment. HP’s premier partners will also have access to our Partner Technology Access Centers (PTACs) to test hp-ux applications on IA-64. HP goal is to ensure that our partners’ transition to IA-64 is as smooth as possible IA-32 and PA-RISC applications are binary compatible to IA-64. Therefore, IA-32 and PA-RISC applications will run unchanged on IA-64. HP is the only RISC vendor who can make this claim. HP recommends, however, that performance sensitive applications be recompiled on IA-64 in order to better exploit the full advantages that the architecture has to offer. Applications that were develop 100% in Java will run unchanged and developers can code with their existing Java tools\

14 HPjconfig hp에서 제공하는 pure Java 로 작성된 hp-ux 커널 tuning tool
JVM 및 커널 파라메타의 설정에 사용 설치된 Java 서비스에 따라 커널 파라메타 값 권고 HPjconfig is a HP Java specific tuning tool that makes recommendations for the kernel and eventually command line JVM parameters. This configuration information is targeted to specific hp-ux hardware platforms to get customers up and running quickly on HP Java enterprise deployments. HPjconfig provides kernel parameter recommendations tailored to the customers HP Java enterprise services (i.e. Web server, Application Server, etc.). It also allows the user to edit parameter formulas to fit their specific needs and view all changes caused by the modification(s). With Save and Restore functionality this makes for easy distribution of tailored recommendations across the customer base. HPjconfig also offers HTML help pages describing the tool’s operation. HPjconfig is a pure Java Application that runs on the hp-ux SDK or JRE for the JavaTM 2 Platform version or later (i.e. for which hp-ux or later is required). HPjconfig version 1.0 can be used to tune the following hardware systems: K420, K580, L , or N with support for addition systems coming in the future. HPjconfig support can be obtained by sending to

15 Hp Java out-of-box for hp-ux 11
Java 를 사용하는 hp-ux 시스템을 즉시 구성 독자적인 bundle 소프트웨어 아래와 같은 Java 어플리케이션을 운영하는 시스템에 적합: 많은 Java 어플리케이션 사용 서버상에서 장시간 운영되는 경우 많은 thread 사용 클라이언트에서 서버로의 접속이 많은 경우 The default HP-UX configuration, specifically kernel parameters and system tunables, does not support certain types of Java applications well. Applications that typically need to be tuned by hand are large, server-side Java applications that are long running, have large numbers of threads, and have a large ratio of client to server connects. Java Out-of-Box is a stand-alone bundle that upon installation will install startup (RC) scripts, modify kernel parameters, rebuild the kernel, and reboot the system. During startup the startup scripts will modify system tunables, thus providing true "out of the box" behavior for Java.

16 HPjmeter hp에서 제공하는 pure Java 로 작성된 profiling tool 어플리케이션 성능의 최적화
bottleneck, method 실행 시간, call count, 메모리 사용량, lock contention, 오브젝트 생성 정보 등의 감지 및 리포팅 어플리케이션의 실행이 종료된 후, Java profile 파일의 분석 및 표시 모든 platform에서 생성된 Java profile 파일의 분석이 가능하고, 특히 hp JVM에서는 확장된 profiling 정보 수집 가능 HPjmeter Helps detects bottlenecks Method execution times, call counts, memory v1.1 currently available on hp-ux 10.20/11.0 HPjmeter is an HP produced tool which analyzes and displays Java profile files after an application has completed running. The tool is 100% Java and will analyze -prof files generated on any platform. HP, however, also offers extended profiling information from it’s JVM. At the thread level, the tool display thread lifetime, helpful in seeing visually how many threads your application is generating and how many are active concurrently.For each method, it also displays the time spent in the method by either wall clock time or CPU time. If the wall clock time is high, but the CPU time is low, the method may be waiting for a lock. Vs Jprobe: insertion based vs. post mortem pay vs. free

17 HPjtune hp 의 Java 성능 분석 tool garbage collection 성능의 향상
기 정의된 그래프를 이용하여 garbage collector 사용량을 표시 항목을 선택할 수 있는 user-configurable 그래프 HPjtune is a tool that helps you analyze garbage collection performance by graphically displaying instrumentation data from the garbage collector. HPjtune lets you view this data in the following ways: Several predefined graphs which show the utilization of garbage collector resources and the impact of the garbage collector on application performance. User-configurable graphs for access to selected garbage collection metrics. Separate predefined graphs for garbage collection behavior pertaining to threads. HPjtune also includes a unique feature which allows you to use collected data to predict the effect of new garbage collector parameters on future application runs. HPjtune displays data for SDK and RTE for Java release or later or 1.3 or later for HP-UX 11.x (PA-RISC and Itanium), HotSpot VM.

18 hp 의 Java 어플리케이션 개발 환경 Design Debug Optimize for HP-UX Code
Development Configure Package Install on HP-UX Deployment Test / Validate WebGain Visual Cafe ParaSoft Jtest HPjmeter jar swinstall HPjconfig ZeroG Install Anywhere TogetherSoft Control Center hp Java out of the box for HP-UX 11 HPjtune Sitraka JProbe Coverage Data Representations Simplicity Sitraka JProbe Profiler Java Web Start This slide shows the tools that are available today plus the tools that are being ported by partners who have made a definite commitment to release on HP-UX (I.e., Sitraka.) All tools on this slide are being actively used by engineers in eJL to ensure that they continue to function properly in the HP environment and that they work together to support the complete development process. The recommended development methodology is to use an NT desktop with remote targeting of the HP-UX server. All of the tools in this collection support this development methodology. An alternative recommendation is to use a Linux desktop. Many of the tools support this methodology in addition to the NT desktop. For further details, this slide is available on HP’s external web site at On the website, each tool name has a hot link to a description page and then to the vendor’s page. Additional tools are in progress and will be added when appropriate. Jprobe profiler: beta 2/22/01 FCS: 4/17/01 Jprobe Coverage, threadAnalyzer: 4/17/01 Rational Rose EMACS MetaMata Debug Wily Tech. Introscope SDK

19 Java JVM Runtime 컴파일러 Garbage Collection 동기화, Monitors, Contention 기타

20 JVM – Java Virtual Machine
class 파일의 로드 Interpreter bytecode 실행 Native runtime bytecodes 를 native instruction으로 변환하는 runtime 컴파일러

21 Java Virtual Machine 의 동작 원리
어플리케이션 Class 파일 Java API Class 파일 class loader class 파일의 로드 interpreter byte code 실행 runtime 컴파일러 byte code 를 native code 로 변환 Class Loader byte code Interpreter 0a0b0c0d0c c1d688662a0b0c0d0c Runtime 컴파일러 native code

22 JVM 의 종류 HotSpot JVM Classic JVM HP-UX에서의 디폴트 JVM
Server- side runtime 컴파일러를 포함 코드를 빠르게 실행하기 위한 최적화 기능 빠른 interpreter Java Heap 및 Garbage Collector bytecodes에서 native code로의 Runtime 컴파일 Classic JVM 1세대 JVM 다음과 같이 기동: java –classic JDK 1.4에서는 지원 안함

23 Runtime 컴파일러 Just-In-Time (JIT) 컴파일러 (Classic JVM)
각 bytecode 를 대응하는 native instruction으로 변환 최적화 부분이 적음 – 아래 사항을 하기위한 내부 데이터 구조가 존재하지 않음: 레지스터 할당 Instruction 스케쥴링 HotSpot Runtime 컴파일러 (Server- side) method 의 bytecode에서 intermediate representation (IR)으로의 변환 호출된 method 의 즉시 처리 Optimizer에서 IR 의 최적화 실행

24 HotSpot JVM 개요 “LongView Technology” 라는 회사에서 개발 Interpreter 코드 실행 분석
Sun에서 LongView 인수 HP에서 기술 라이센스 HP-UX 에 맞게 HP에서 최적화 Interpreter Runtime 라이브러리 Java Heap 및 Garbage Collector 코드 실행 분석 프로그램 실행시 “hot” spot 을 인식 Runtime 컴파일러에서 최적화를 하여 코드 컴파일 중요 method 의 즉시 처리

25 HotSpot JVM 개요 주요 장점: 서버상에서 장시간 운영되는 어플리케이션을 위한 구조 가볍고 부하가 적은 오브젝트 모델
빠른 garbage collector 빠른 동기화 Adaptive compilation 서버상에서 장시간 운영되는 어플리케이션을 위한 구조 JVM 의 옵션을 사용하여 client-side 어플리케이션을 위한 구성 가능

26 HotSpot Runtime 컴파일러의 동작 원리
Java Class File Class 파일 프로그램 실행시의 코드 분석 adaptive optimization 프로그램 실행 시 “hot” spot 을 인식 실행 시간에 따라 native code 로 컴파일 서버상에서 장시간 운영되는 어플리케이션을 위한 구조 기동 시간이 늦을 수 있다. client-side 어플리케이션을 위해 기동 시간을 빠르게 구성 가능 Interpreter HotSpot Runtime 컴파일러 이 method 가 많이 사용! native code 로 컴파일 byte code 0a0b0c0d0c c1d688662a0b0c0d0c native code Classic JVM First generation JVM Invoked using: java -classic Obsolete in JDK 1.4 Execution Throughput Time

27 HotSpot Runtime 컴파일러 Classic JIT 컴파일러 HotSpot Runtime 컴파일러
실행 빈도에 따른 컴파일 HotSpot Runtime 컴파일러 Adaptive optimization 어플리케이션 Profile 기능 Method 의 호출 빈도 Stack trace 실행 시간에 따른 컴파일 stack trace 에 따른 즉시 처리

28 HotSpot Runtime 컴파일러의 장점
더 적은 양의 코드만 컴파일됨 더 적은 양의 코드 캐쉬 필요 컴파일된 코드의 더 높은 optimization level 지원 Reoptimization interpreted method 를 다시 실행하도록 바뀐다. Interpreter에서 bytecode 버전 method 호출 적절한 때에 해당 method 가 재 컴파일 됨 프로그램 동작에 따른 적절한 대응 다른 실행 경로 -> 다른 처리 정확한 프로그램 실행을 위해 필요함

29 garbage collection JVM 의 내장된 기능 자동으로 더이상 사용하지 않는 메모리를 재활용
레퍼런스가 없는 오브젝트를 제거하고, 해당 레퍼런스가 점유하고 있던 공간을 사용 가능하게 한다. 최적의 어플리케이션 성능은: 한번의 collection 에 필요한 시간이 너무 오래 걸리지 않도록 한다. 모든 collection 에 사용되는 시간을 줄여 최적의 throughput 을 얻을 수 있도록 한다. 5 10 15 20 25 Seconds 8 768 MB Heap 384MB Heap Garbage collection is a serious consideration of JVM performance. The text describes what GC does. The picture can be used to explain why “just make the heap bigger” is not an optimum strategy. The graph that shows both the lower overall collection time (green 15 seconds column) and individual 8 second collection event times for each GC event on a smaller heap (red column). The moral of the story is that a larger heap may give longer individual collection times for each GC event (15 seconds), but a shorter overall time for the sum of times for all GCs (15 versus 24 seconds). there is a tension between providing shorter pauses times (shorter individual collection events) and maximizing overall throughput (providing a shorter overall sum of all collection times). With a smaller heap, you may have shorter individual collection times, but since there is a need for more collection events, to scramble for memory, then the sum of all collection times may be greater than one longer collection time in a big heap. With a larger heap, individual GC-caused pauses will be longer, but the application work throughout may be higher, since there are fewer such pauses. This seems like a lot of information, but it is easily fixable by the TC, if they just study the -Xverbosegc data - and so in a sense it is a low-hanging fruit for the performance person. It is sure to win the confidence of customers, if the TCs take time to understand it. 예제: 전체 GC 시간의 35% 감소

30 동기화, Monitor, Contention
공유 자원으로의 억세스를 제어한다. Java monitor 가 억세스를 제어한다. For any given shared resource, threads cannot have simultaneous access. Java monitors control access to the shared resources by requiring that the thread obtain a lock before accessing the shared resource. While the one thread has access to the shared resource, the other threads are stopped until the lock is available.

31 JNI – C/C++ 을 위한 Java Native Interface
Exception Class VM 기존 C 코드 Native Interface 함수 라이브러리 access C/C++ programs from Java Java runtime from C/C++ programs no need to throw away all that legacy code, the JNI API solves this language interaction problem

32 기타 유용한 용어 JNDI J2EE Java Naming and Directory Interface
J2EE 어플리케이션 서버에서 오브젝트/ beans 를 찾기 위해 사용 LDAP 서버와 인터페이스 가능 J2EE Java 2 Enterprise Edition J2SE + 어플리케이션 서버에서 필요로 하는 라이브러리

33 J2EE J2EE 란? Servlet JSP EJB 어플리케이션 서버

34 J2EE 를 왜 사용하는가? 전통적인 개발자가 고려하여야 할 사항 위의 모든 것을 J2EE 어플리케이션 서버에서 관리
로깅 기능 원격 클라이언트 원격 관리 리소스 pooling 동기화 로그인 관련 트랜젝션 프로세싱 multi-threading… 위의 모든 것을 J2EE 어플리케이션 서버에서 관리 개발 비용 및 복잡도의 감소 신속한 deployment 가능 모듈화로 코드의 재활용도를 높임 This is an opportunity to review the benefits of J2EE discussed in the J2EE components presentation J2EE reduces cost and complexity This is only true if you consider the cost of building and maintaining your own infrastructure, providing such things as transaction management, messaging, security, resource management, TP Monitor type functionality. Because this infrastructure already exists, the relative cost for a specific quality of application is reduced because the developers focus specifically on the business logic in the EJBs and Servlets. J2EE enables rapid development and deployment As mentioned above, the fact that the developer only has to focus on business logic specific to the problem domain means that they become much more productive. With the addition of enterprise class development tools, this task becomes much more efficient. It should be pointed out that this is not an all or nothing proposition. Some development teams may avoid J2EE because they don’t trust or want to use EJBs. It is possible to get just a Servlet/JSP engine, just a JMS server or even just a JTS server. A developer is not required to make use of all of J2EE for their application.

35 J2EE 상세 사항 Java 2 Platform, Enterprise Edition
Remote Method Invocation Simple Distributed Communications API RMI-IIOP adds CORBA interoperability Java 2 Platform Standard Edition Core Java platform language and services, such as java.io, java.util, applets, applications, JFC, etc Enterprise JavaBeans Component standard Defines the overall Server-side architecture Defines interfaces between software vendors and clients Ties together the other APIs Naming and Directory Interface Provides a namespace for finding components and resources Java Messaging Service Asynchronous Invocations Publish/Subscribe , or Point-to-point Transactional messages Java 2 Platform, Enterprise Edition Database Connectivity Provides a unified API for accessing relational databases Transaction API Defines the high-level interface for demarcating transactional boundaries Java Transaction Service (JTS) defines a low-level interfaces between transaction participants JavaMail Allows you to perform operations in a cross-platform, cross-protocol fashion Also requires JavaBeans Activation Framework There are a lot of different ways of looking at the specification. On top of that, the specification has changed over time. This particular view comes from Mastering Enterprise JavaBeans and the Java 2 Platform, Enterprise Edition by Ed Roman, published by Wiley. It is important to give credit for this! In addition, the specification talks about security and a defined set of platform roles for various aspects of the specification. The next two slides will cover this before looking at the APIs themselves. Connectors Provides access to existing enterprise information systems Servlets and Java Server Pages Request/Response oriented network components Typical use is in web server for client-side interaction Scripting capability Java IDL CORBA provides language interoperability Integration with existing systems XML Describes EJB components Format for JSP scripts Other future uses as well

36 Java servlet 웹서버에서 동작하는 Java 프로그램 CGI 와 유사하지만 더욱 향상된 기능 제공
향상된 성능 세션 정보의 유지 가능 Applet 이 웹 브라우저를 필요로 하는 것과 같이, 실행 환경 (웹 서버)을 필요로 한다. 일반적으로 HTML 을 생성하고 리턴한다. A servlet is a special class of java application that typically runs in a web server, at least that’s its origin. These days most application servers support Servlets as well. The servlet APIs support the same request/response capabilities as CGI (handling get and post operations) but can run in the same process space as the web server. This provides much better performance than is seen by CGI programs where the web server must fork the process that will run the CGI program. Just as an applet extends the core Java class Applet and requires a web browser to run in, servlet programs extends the Java class Servlet (more properly, HttpServlet) and requires a web server or application server to “host” it. In HTML file, access the servlet by using the <SERVLET> tag. Servlets allow a thin client in that all the logic actually runs on middle tier in the web server space. What is sent to the servlet is information gathered from an HTML form much just like CGI. What is returned to the browser is HTML (or XML) code that is generated by the servlet. The next couple of slides show how this works.

37 Java servlet 의 사용 Backend 서버 Web Container 클라이언트 CGI 와 유사하지만: 향상된 성능
Hello.htm 파일 Backend 서버 <HTML><HEAD> . . .</HEAD> <BODY> ... <FORM METHOD=GET ACTION=‘/servlet/Hello’> Name please: <INPUT TYPE=INPUT Name=‘name’><P> <INPUT TYPE=SUBMIT> </FORM> </BODY> </HTML> Web Container 클라이언트 요청 응답 Servlet server-side Java program requires a runtime environment (the web container) much like applets require a web browser like CGI but better - Better performance because they can run "in process" with web server, often pre-loaded, and don't require a fork for every request - can maintain state because servlet container provides this functionality and APIs make it easy most used for flow control – but can create and return HTML supports the idea of thin client A web browser would reference Hello.htm from a particular web server that supports Servlets. What the user would see is a simple form with a text field and a submit button. Upon entering a name and pressing the submit button, the form information would be sent to the servlet “Hello” referenced in the form specification. The servlet would execute, generating HTML that would be sent back to the web browser. This example is just a simple Hello world example. One could imagine a fairly complex user interface layout with a lot of information being gathered. The advantage is that the client is still ‘thin’ and it can run from outside a firewall (via proxy server) CGI 와 유사하지만: 향상된 성능 세션 정보의 유지 가능

38 servlet 코드 import java.io.*; import javax.servlet.*;
import javax.servlet.http.*; public class Hello extends HttpServlet { public void doGet(Http ServletRequest req, HttpServlet Response res) throws ServletException, IOException { res.setContentType(“text/html”); PrintWriter out = res.getWriter(); String name = req.getParameter(“name”); out.println(“<HTML>”); out.println(“<HEAD><TITLE>Hello, “ + name + “</TITLE></HEAD>”); out.println(“<BODY>”); out.println(“Hello, “ + name); out.println(“</BODY></HTML> } This is the actual servlet code. Note that class Hello extends HttpServlet. This code is compiled using standard javac and the resulting Hello.class file is stored in the standard servlet path that is configured in the web server. Note that all this program does is simple HTML code generation using information obtained from the form. This information could be used to do a number of things. Make a JDBC call, formatting the result into HTML for user presentation Call another servlet or JSP (we’ll see what those are next) Call one or more EJB objects etc Note also that the entire resulting web page must be returned back including the HTML tag, the HEAD tag. Servlet technology tends to combine both the presentation logic with the data gathering logic.

39 Java Server Pages (JSP)
개념상 servlet 과 유사 HTML 안의 Java Java 는 실행 전에 web container에서 컴파일 됨 JSP 를 사용하면, presentation 과 데이터 수집부의 분리가 가능 JSP에서 JavaBeans 또는 EJB 사용 가능 Allows for Java code to be directly inserted into a standard HTML document but requires the following: The web server must have a JSP engine or be enabled to integrate a third party one or can be in an application server JSP files are typically noted with the .jsp extension to indicate to the server to activate the JSP engine JSP allows the separation of presentation design from development of code used to provide the dynamic data content The JSP engine handles generating the equivalent servlet code that actually gets executed Like Servlets, JSP can make use of other technologies like JavaBeans, EJB, and JDBC therefore allowing robust middle tier solutions You can use HTML or XML for the presentation and JSP ‘scriptlets’ to gather the data JSP is seen to be a direct competitor to Microsoft’s Active Server Pages. In reality, there are a number of advantages of JSP over ASP. Likely won’t get into this too much unless asked but two main ones are: ASP needs to be compiled every time it is accessed Only IIS supports ASP JSP can use session state to retrieve information from a previous client invocation. ASP can’t do that

40 Java Server Page (JSP) 의 사용
Backend 서버 <HTML><HEAD>. . .</HEAD> <BODY> ... <% if (request.getParameter( ‘name’) == null) { %> Hello World <% } else { %> Hello <%=request.getParameter( ‘name’) %> <% } %> </BODY> </HTML> Web Container 요청 클라이언트 Java 컴파일러 Servlet 응답 Java code is embedded in the HTML file is compiled into a servlet by the web container before it is executed with JSP, you can separate the presentation from the data gathering; better when focus is on presentation and a little business logic is required JSP can use other Java classes, such as JavaBeans or EJBs When the web server receives a request for a jsp page, it will automatically run it through the JSP engine, which will generate the supporting Java code making it look like a servlet. This code is then compiled using javac to create an actual class file that will be executed by the servlet engine. One advantage JSP has over Servlets is that then entire result page doesn’t need to be composed in the servlet. Often there are “static” portions of the page that are more easily supported as typical HTML or XML. With JSP, you only need to use Java for the dynamic portions of the page. JSP tends to support a model that separates the content gathering from the presentation. Presentation is handled by HTML or XML while the content gathering is handled by the JSP fragments. Another advantage of JSP is that it tends to promote the re-use of components (Beans or EJB). The fact that it it is easy to refer to these components and use them means that a developer quickly becomes more productive by re-using these components. presentation 과 데이터의 분리 JavaBean 또는 EJB 와 같은 Java class 사용 가능

41 Enterprise Java Bean 아키텍쳐
J2EE 환경에서 가장 중요한 부분 단순한 API 가 아님 – 실행 환경에 대한 정의 두 가지 종류의 component 정의 session bean entity bean EJB is really almost the centerpiece of J2EE. It uses or depends on almost every other technology in the specification. Here, we revisit the idea that EJBs must have a runtime environment. As we will see later, this is the EJB container, typically provided by Application Servers. Session beans can either maintain state locally or not. There are no built in mechanisms in Session beans for persistent storage of the state. An example of a stateful Session bean would be an online shopping cart. Entity beans can either manage their own persistence via JDBC or some other mechanism, or allow the container to manage

42 enterprise 어플리케이션 개발 모델
Note that this picture from Sun uses different tier names than we have used. It may be worth pointing out just to eliminate confusion. According to Sun’s Blueprints, they now partition the middle tier into a web server tier which provides the presentation using Servlets and JSP, and the app server or business logic tier, which hosts the EJBs that access databases and other enterprise information systems. NOTE: we have been calling this the data tier. Note that Sun often refers to the container for JSPs and Servlets as the Web Container. It is worth pointing out that in many cases, these capabilities are provided on the same server and by the same application server. For scalability reasons, it may make sense to distribute these two components into server side presentation and server side business logic.

43 J2EE 어플리케이션 서버란? 어플리케이션 서버는 component 기반의 제픔으로 서버 중심의 아키텍처에서 middle-tier 에 존재한다. 상태 유지, 데이터 억세스 및 유지와 같은 미들웨어 서비스를 제공한다. 데이터베이스 서버 어플리케이션 EIS Tier APIs 브라우저 Middle Tier Client Tier J2EE Platform EJB 서버 Web 서버 An application server is a component-based product that resides in the middle-tier of a server centric architecture. It provides middleware services for security and state maintenance, along with data access and persistence. Java application servers are based on the Java™ 2 Platform, Enterprise Edition (J2EE™). J2EE uses a multi-tier distributed model. This model generally includes a Client Tier, a Middle Tier, and an EIS Tier. The Client Tier can be one or more applications or browsers. The J2EE Platform is in the Middle Tier and consists of a Web Server and an EJB Server. (These servers are also called "containers.") There can be additional sub-tiers in the middle tier. The Enterprise Information System (EIS) tier has the existing applications, files, and databases. For the storage of business data, the J2EE platform requires a database that is accessible through the JDBC, SQLJ, or JDO API. The database may be accessible from web components, enterprise beans, and application client components. The database need not be accessible from applets. Security: some amount provided, role-based security. But no one is using it.

44 어플리케이션 서버의 역활 component 를 위한 container 제공
지원되는 모든 서비스 제공 (pooling, 트랜젝션 관리) 리소스 사용의 관리 어느 정도까지의 보안 제공 웸 서버를 제공하거나 웹 서버에 plug in 됨 Application servers generally provide the container for the components, although it is possible for another vendor to provide the container. As an example, BEA provides WebLogic Server, which has a basic container. TopLink from WebGain also has a more sophisticated container that supports more complex object -> relational mapping. The container is responsible for managing the lifecycle of the objects as well as managing access to them and providing access to all the other services. The application server typically provides the required services. A J2EE compliant application server MUST provide all the required services to claim J2EE support, although a class of servers are available that just provide JSP and Servlet support or just JMS support. In addition application servers typically provide management of access to resources and provides mechanisms to assure scalability. Client connection management Database connection pooling Data caching Application servers typically provide some form of security as mentioned earlier. Most will provide authentication mechanisms, authorization management, security domains and user roles It is interesting to note that many web servers are now called Web Application Servers because they provide both traditional web server capabilities as well as application server capabilities. Most can also plug in to web servers using ISAPI or NSAPI

45


Download ppt "Java 소개 2003.1.21 강사 : 이욱준 차장(MCSC)."
Ads by Google