วันอังคารที่ 29 กรกฎาคม พ.ศ. 2551

Config Servlet Cache Instances [On Websphere 6.0-6.1]

จะสอนวิธี Config Servlet Cache ของ Websphere ซึ่งมีวิธี 3 แบบครับ

ฮธิบายก่อน Servlet Cache คือ การเก็บค่าไว้โดยที่ไม่ต้องทำการประมวณผลใหม่ในกรณีที่เราเข้ามาด้วย parameter เดิมนะครับ (ที่จริงมีกำหนดหลายแบบ ผมขอบอกเฉพาะที่เป็น Parameter นะครับ) เช่น สมมตผมกำหนด ว่าให้ Servlet SampleCache ไว้เป็น Servlet Cache แล้วกำหนด Parameter ให้ productId เป็นไว้ เมื่อเราเข้าหน้าเวบด้วย productId=1 ครั้งแรกจะยังเข้า Servlet อยู่ แล้วครั้งต่อๆ ไปพอเราลอง Refresh หน้าดูแล้วจะไม่มีการเข้าไปใน Process ของ Servlet อีกครับ จะใช้ค่าเดิมที่เราเข้าไปครั้งแรกเลย (สามารถกำหนด Timeout ได้ครับ)

เราต้อง Config ให้ Websphere ใช้งาน Servlet Cache ก่อนโดย

  1. ไปที่ Servers --> Application Servers
  2. แล้วเลือก Server ที่เราต้องการจะ Config Servlet Cache
  3. ดูที่ทางขวา จะมี Container Settings ให้เลือกที่ Web Container Settings --> Web Container
  4. พอกดเข้าไปจะเห็น Enable Servlet Caching แล้วติ๊ก
  5. พอทำเสร็จก็ Restart Server ครับ เป็นอัน Config Servlet Cache ให้ใช้งานได้ล่ะ

ต่อไปเรามา Config Servlet Cache ที่เครื่องเราต่อ (ผมใช้ Config จาก cachespec.xml) ตอนแรกเราจะต้องไปเอา cachespec.xml, cachespec.dtd มาก่อน โดยจะอยู่ที่ xxx\base_v6\properties ครับ แล้ว Copy มาไว้ที่ Project ของเรา ที่ Path --> WEB-INF


แบบที่ 1 จะเป็นการ Config ให้ดูที่ Path

<cache-entry>
<class>servlet</class> --> กำนหดให้เป็นชนิด Servlet
<name>/ProductDisplay</name> --> Servlet Path ชื่อนี้
<cache-id>
<component id="productId" type="parameter"> --> กำหนดให้ Parameter ที่ส่งมาถ้ามีตัวนี้ ซ้ำ จะไม่ทำงานซ้ำ
<required>true</required> --> จำเป็นจะต้องมี Parameter ตัวนี้ส่งมาหรือเปล่า
</component>
<timeout>180</timeout> --> กำหนด Timeout ของ Servlet Cache
</cache-id>
</cache-entry>

แบบที่ 2 กำหนดที่ตัว Class เลย

<cache-entry>
<class>servlet</class>
<name>com.webpage.servlet.ProductDisplay2.class</name> --> บอกว่าเป็น Servlet Class ไหน
<cache-id>
<component id="productId" type="parameter">
<required>true</required>
</component>
<timeout>300</timeout>
</cache-id>
</cache-entry>


แบบที่ 3 จะคล้ายๆ กับแบบแรก แต่จะใช้ Servlet Cache ของ Application Server เลย

<cache-instance name="cache/servlet/sample"> --> กำหนด JNDI Name ของ Servlet Cache
<cache-entry>
<class>servlet</class>
<name>/ProductDisplay3</name>
<cache-id>
<component id="productId" type="parameter">
<required>true</required>
</component>
<timeout>180</timeout>
</cache-id>
</cache-entry>
</cache-instance>


วิธี Config Servlet Cache ของ Application Server

  1. ให้ไปที่ Resources --> Cache instances --> Servlet cache instances
  2. คลิกเข้ามาเสร็จ ก็เลือก New
  3. แล้วกำหนดชื่อ JNDI Name ให้เป็นชื่อเดียวกับ ที่เรากำหนดใน cachespec.xml
  4. Save แล้วก็ Restart Server เป็นอันเสร็จ


Reference
http://www.webagesolutions.com/knowledgebase/waskb/waskb008/index.html

Related Posts:

  • Config Servlet Cache Instances [On Websphere 6.0-6.1]จะสอนวิธี Config Servlet Cache ของ Websphere ซึ่งมีวิธี 3 แบบครับฮธิบายก่อน Servlet Cache คือ การเก็บค่าไว้โดยที่ไม่ต้องทำการประมวณผลใหม่ในกรณีที่เราเ… Read More
  • Path Log ของ XA DatasourcePath จะอยู๋ประมาณนี้น่ะครับ จะอยู๋ใน tranlog น่ะครับในแต่ละ Profiles ซึ่งสาเหตุที่เราไปลบเพราะว่า บางทีWebsphere จะมี Log Error ค้างอยู่ใน Server ซึ่ง… Read More
  • Data store tables Table namePurposeSIBOWNEREnsure exclusive access to the data store by an active messaging engineSIBCLASSMAPCatalogs the different object types in the… Read More
  • วิธีแก้ว่าไม่สามารถใช้ Datasource ที่สร้างใหม่ได้คือเวลาสร้างเสร็จแล้วลอง Test Connection แล้วไม่สามารถที่จะ Test ผ่านน่ะครับ จะขึ้นประมาณว่าinvalid arguments in callDSRA0010E: SQL State = null, Erro… Read More
  • ปัญหาการ Deploy บน Websphere 6.0 - 6.1ปัญหาส่วนใหญ่ต้องดู SystemOut.log เอาน่ะครับ อันนี้เป็น Guidline คร่าวๆ เท่านั้น1. ถ้าเคย Deploy แล้วได้ แต่อยู่ดีๆ พอ Deploy ใหม่แล้วไม่ได้ ลอง Expor… Read More