10_Servlet - CSI 3540 Structures, techniques et normes du...

Info iconThis preview shows pages 1–15. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSI 3540 Structures, techniques et normes du Web Tuesday, February 9, 2010 Objectif: Introduction la programmation ct serveur Introduction aux Servlets Lectures: Web Technologies (2007) 6 Pages 323350 Programmation ct serveur : Servlets Tuesday, February 9, 2010 Plan 1. Traitements parallles 2. Autres mthodes du Servlet Tuesday, February 9, 2010 Traitements parallles Tuesday, February 9, 2010 Traitements parallles (//) Ct client : les fureteurs tlchargent plusieurs images simultanment ou encore plusieurs onglets (tab ) tlchargent plusieurs pages simultanment Ct serveur : des centaines, voir mme des milliers, dusagers accdent le serveur simultanment Tuesday, February 9, 2010 Traitements parallles en Java Pour nos besoins, il ny a qu une instance du Servlet Mais chaque requte de lusager est traite par un flin dexcution qui lui est propre. Ainsi, plusieurs flins excutent counter.doGet() simultanment Tuesday, February 9, 2010 public class SlowGetUid extends HttpServlet { private int lastUid = 1000; public void doGet ( HttpServletRequest requete , HttpServletResponse reponse ) throws ServletException , IOException { . . . String uidStr = Integer.toString( lastUid + 1 ); try { Thread.sleep( 1000 * 5 ); } catch ( InterruptedException e ) { System.err.println( "** InterruptedException caught **" ); } lastUid++; // gnration du document doc.println( "<!DOCTYPE html" ); ... doc.println( " Votre code d'accès est le : <b>" + uidStr + "</b>!" ); ... } } // variable dinstance // on simule on long traitement Tuesday, February 9, 2010 Traitements parallles Tuesday, February 9, 2010 Traitements parallles Filin 1 uidStr = Integer.toString( lastUid + 1 ); uidStr = Integer.toString( lastUid + 1 ); lastUid++; lastUid++; Filin 2 Temps t t Tuesday, February 9, 2010 Traitements parallles en Java Chaque flin dexcution possde sa propre pile dappels (variables locales, paramtres, compteur de programme, etc.) Par contre, les variables d instanc e et de classe , ainsi que les ressources externes , par exemple les fchiers, sont partages Tuesday, February 9, 2010 Traitements parallles en Java Accs en lecture . Certains accs simultans ne posent aucun problme. Les objets accds en lecture seulement ou immuables. Par exemple, un dictionnaire de mots. Tuesday, February 9, 2010 synchronized Mthode synchronized La JVM cre automiquement un verrou pour chaque objet ou classe Lorsquun flin excute une mthode synchronized il dtient le verrou de lobjet ou de la classe Aucun autre flin ne peut excuter une mthode de cet objet ou de cette classe Tuesday, February 9, 2010 synchronized private synchronized String getUid() { String uidStr = Integer.toString( lastUid + 1 ); try { Thread.sleep( 1000 * 5 ); } catch ( InterruptedException e ) { System.err.println( "** InterruptedException caught **" ); } lastUid++; return uidStr; } Tuesday, February 9, 2010 synchronized Tuesday, February 9, 2010 synchronized...
View Full Document

This note was uploaded on 06/07/2010 for the course CSI ITI1520 taught by Professor Marcelturcotte during the Spring '10 term at University of Ottawa.

Page1 / 46

10_Servlet - CSI 3540 Structures, techniques et normes du...

This preview shows document pages 1 - 15. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online