Topic
2 replies Latest Post - ‏2007-06-07T17:32:07Z by SystemAdmin
SystemAdmin
SystemAdmin
210 Posts
ACCEPTED ANSWER

Pinned topic a inefficient JSP page, too much time need to wait

‏2007-06-07T04:28:24Z |
The page below is too much inefficient,the user must wait for about 10 minutes or more...

<%@ taglib uri="/bean" prefix="bean"%>
<%@ taglib uri="/html" prefix="html"%>
<%@ page import="com.actual.inventory.*" contentType="text/html;charset=big5"%>
<%@ page import="com.rover.*"%>

<%@ include file="../global/connection.inc"%>
<%
String group=doc.getUTF(request.getParameter("group"));
String emp_no=doc.getUTF(request.getParameter("emp_no"));
java.sql.Date limit_date=SqlProcess.getLimitTime(conn);
long quantitytemp=0;
String today="";
String from_date="20070312";
String to_date="";
/*
sql="select to_char(sysdate-56,'yyyymmdd') from dual";
rs=stmt.executeQuery(sql);
if(rs.first()){
from_date=doc.getPost(rs.getString(1));
}rs.close();
*/
sql="select max(c_date) from v_new_balance_t";
rs=stmt.executeQuery(sql);
if(rs.first()){
to_date=doc.getPost(rs.getString(1));
}rs.close();
int i=0;
String user_id=request.getRemoteUser();
String user_name="";
sql="SELECT C_NAME FROM C_USER_T WHERE C_ID='"WC.htmlEncode(user_id)"'";
rs=stmt.executeQuery(sql);
if(rs.first()){
user_name=doc.getPost(rs.getString(1));
}rs.close();
Phase phase=new Phase();
FormatWeek FW=new FormatWeek();
GetMonday GM=new GetMonday();
GetSunday GS=new GetSunday();
String first_week=FW.getWeekNum(FW.getweek(from_date));
String last_week=FW.getWeekNum(FW.getweek(to_date));
String first_date=GM.getmonday(first_week.substring(0,4),first_week.substring(4,6));
String last_date=GS.getsunday(last_week.substring(0,4),last_week.substring(4,6));
java.sql.Datehttp://] date_array=(java.sql.Date[)((ArrayList)phase.getPhase(doc.getDate(first_date),doc.getDate(last_date))).toArray(new java.sql.Date[0]);
String] week_array=(String[)((ArrayList)phase.getFormatWeekPhase(first_week,last_week)).toArray(new String[0]);
String[] week_count_array=new Stringhttp://week_array.length;
for(i=0;i[week_array.length;i++)
{
week_count_array[i]=String.valueOf(phase.getWeekCount(week_array[i]));
}
String[] date_week_array=new Stringhttp://date_array.length;
for(i=0;i[date_array.length;i++)
{
date_week_array[i]=FW.getWeekNum(FW.getweek(doc.getDateValue(String.valueOf(date_array[i]))));
}
/* Total? */
long productcum=0;
long deliverycum=0;
long[] product_cum=new longhttp://date_array.length;
long[] delivery_cum=new longhttp://date_array.length;
//HashMap hh_pn = new HashMap();
HashMap product_req=new HashMap();
HashMap additional_req=new HashMap();
HashMap c_delivery=new HashMap();
HashMap sc_in=new HashMap();
HashMap sc_out=new HashMap();
HashMap c_balance=new HashMap();
HashMap tiptop_stock=new HashMap();

//before
HashMap product_before=new HashMap();
HashMap delivery_before=new HashMap();
HashMap sc_in_before=new HashMap();
HashMap sc_out_before=new HashMap();
HashMap balance_qty_before=new HashMap();

//Accumulation before
HashMap product_cum_before=new HashMap();
HashMap delivery_cum_before=new HashMap();
HashMap sc_in_cum_before=new HashMap();
HashMap sc_out_cum_before=new HashMap();
%>

tr
td
: <%=first_date.substring(0,4)+"/"first_date.substring(4,6)"/"first_date.substring(6,8)%> - <%=last_date.substring(0,4)"/"last_date.substring(4,6)"/"+last_date.substring(6,8)%>[/div]
[/td]
[/tr]
tr
td
: <%=user_name%>[/div]
[/td]
[/tr]
tr
td
[B] : [U]<%=SqlProcess.getSystemTimestamp(conn)%>[/U][/B][/div]
[/td]
[/tr]
tr
td

tr

[b]HH P/N[/b][/div]
[/td]
[!--
[b]---------------SONY P/N[/b][/div]
[/td] --]

[b]Description[/b][/div]
[/td]

[b]Item[/b][/div]
[/td]

[b]Before[/b][/div]
[/td]
<%
for(i=0;i[week_array.length;i++)
{
%>
[td nowrap colspan="<%=week_count_array
[B]<%=doc.getShow(week_array[i].substring(0,4)+"Y . "week_array[i].substring(4,6)"W")%>[/div]
[/td]
<%}%>
[/tr]
tr
<%
for(i=0;i[date_array.length;i++)
{
%>
td nowrap
<%=doc.getShow(phase.getWeekName(date_array[i]))%>[/div]
[/td]
<%}%>
[/tr]
tr
<%
for(i=0;i[date_array.length;i++)
{
%>
td nowrap
<%=doc.getShow(String.valueOf(date_array[i]).substring(5,10).replaceAll("-", "/"))%>[/div]
[/td]
<%}%>
[/tr]
<%
sql="select distinct v.hh_pn,v.hh_description "+
"from v_new_balance_t a,v_item_info_t v "+
"where a.hh_pn=v.hh_pn and a.version='"group"'";
if(!emp_no.equals("ALL"))
{
sql+=" and v.hh_pn in(select hh_pn from r_user_model_t where user_id='"emp_no"')";
}
sql+=" and a.c_date]='"first_date"' and a.c_date[='"last_date"'";

rs=stmt.executeQuery(sql);
while(rs.next()){
String hh = rs.getString(1);
int modelcount=0;
Vector model=new Vector();
sql2="select a.child_pn,substr(v.customer_code,0,4) "+
"from v_kp_prq_t a,v_vpn_t@no_consign.foxconn.com v "+
"where a.hh_pn=v.hh_pn";
if(group.equals("ON_THE_NB"))
{
sql2+=" and v.hh_pn in(select hh_pn from v_vpn_t@no_consign.foxconn.com where trade_model is null and customer_code in(select customer_name from c_customer_group_t@no_consign.foxconn.com where group_name='NB'))";
}
if(group.equals("ON_THE_DH"))
{
sql2+=" and v.hh_pn in(select hh_pn from v_vpn_t@no_consign.foxconn.com where trade_model is null and customer_code in(select customer_name from c_customer_group_t@no_consign.foxconn.com where group_name='DH'))";
}
if(group.equals("ON_THE_CSCM"))
{
sql2+=" and v.hh_pn in(select hh_pn from v_vpn_t@no_consign.foxconn.com where trade_model='CN')";
}
sql2+=" and a.child_pn='"hh"'";
sql2+=" and a.required_date]='"first_date"' and a.required_date[='"last_date"'";
//out.println("");
rs2=stmt2.executeQuery(sql2);
while(rs2.next())
{
String item_num_tmp = rs2.getString(2);
if(!model.contains(item_num_tmp))
{
model.add(item_num_tmp);
modelcount+=1;
}
}
rs2.close();
HashMap required_quantity=new HashMap();
sql2="select a.child_pn,substr(v.customer_code,0,4),required_date,sum(required_quantity) "+
"from v_kp_prq_t a,v_vpn_t@no_consign.foxconn.com v "+
"where a.hh_pn=v.hh_pn";
if(group.equals("ON_THE_NB"))
{
sql2+=" and v.hh_pn in(select hh_pn from v_vpn_t@no_consign.foxconn.com where trade_model is null and customer_code in(select customer_name from c_customer_group_t@no_consign.foxconn.com where group_name='NB'))";
}
if(group.equals("ON_THE_DH"))
{
sql2+=" and v.hh_pn in(select hh_pn from v_vpn_t@no_consign.foxconn.com where trade_model is null and customer_code in(select customer_name from c_customer_group_t@no_consign.foxconn.com where group_name='DH'))";
}
if(group.equals("ON_THE_CSCM"))
{
sql2+=" and v.hh_pn in(select hh_pn from v_vpn_t@no_consign.foxconn.com where trade_model='CN')";
}
sql2+=" and a.child_pn='"hh"'"+
" and a.required_date]='"first_date"' and a.required_date[='"last_date"' "+
" group by a.child_pn,substr(v.customer_code,0,4),required_date";
rs2=stmt2.executeQuery(sql2);
while(rs2.next())
{
required_quantity.put(rs2.getString(1)+rs2.getString(2)+rs2.getString(3),rs2.getString(4));
}
rs2.close();
String model0=" ";
if(model.size()!=0)
{
model0=(String)model.get(0);
}
if(modelcount==0)
{
modelcount=1;
}

sql="select hh_pn,c_date,product_req,additional_req,c_delivery,c_balance "+
"from v_new_balance_t "+
"where version='"group"' "+
"and c_date]='"first_date"' and c_date[='"last_date"' and hh_pn='"hh"'";
if(!emp_no.equals("ALL"))
{
sql+=" and hh_pn in(select hh_pn from r_user_model_t where user_id='"emp_no"')";
}
rs2=stmt2.executeQuery(sql);
Get_qrt get_qrt = new Get_qrt();
while(rs2.next())
{
String hh_pn_tmp = doc.getPost(rs2.getString(1));
String c_date_tmp = doc.getPost(rs2.getString(2));
product_req.put(hh_pn_tmp+c_date_tmp,rs2.getString(3));
additional_req.put(hh_pn_tmp+c_date_tmp,rs2.getString(4));
c_delivery.put(hh_pn_tmp+c_date_tmp,rs2.getString(5));
c_balance.put(hh_pn_tmp+c_date_tmp,rs2.getString("c_balance"));

get_qrt.get_stmt(conn);
String sql_sc_in = "select quantity from r_replace_online_t where master_kp='"hh_pn_tmp"' and work_date = '"c_date_tmp"' and version='"group"'";
get_qrt.get_qrt(sql_sc_in,sc_in,hh_pn_tmp,c_date_tmp);
String sql_sc_out = "select quantity from r_replace_online_t where replace_kp='"hh_pn_tmp"' and work_date = '"c_date_tmp"' and version='"group"'";
get_qrt.get_qrt(sql_sc_out,sc_out,hh_pn_tmp,c_date_tmp);
String sql_tiptop_stock = "select quantity from data_from_tiptop where hh_pn='"hh_pn_tmp"' and the_date = '"c_date_tmp"' and version='"group"'";
get_qrt.get_qrt(sql_tiptop_stock,tiptop_stock,hh_pn_tmp,c_date_tmp);
get_qrt.close();
}

//Delivery Plan
HashMap delivery_plan=new HashMap();
sql="select hh_pn,delivery_date,quantity "+
"from v_delivery_plan_t "+
"where version='"group"' "+
"and delivery_date]='"first_date"' and delivery_date[='"last_date"' and hh_pn='"hh"'";
if(!emp_no.equals("ALL"))
{
sql+=" and hh_pn in(select hh_pn from r_user_model_t where user_id='"emp_no"')";
}

rs2=stmt2.executeQuery(sql);
while(rs2.next())
{
delivery_plan.put(rs2.getString(1)+rs2.getString(2),rs2.getString(3));
}

sql="select hh_pn,sum(pp_accum_qty),sum(delivery_accum_qty),sum(sc_in),sum(sc_out),sum(balance_qty) "+
"from v_balance_before_t where version='"group"' and hh_pn='"hh"'";
if(!emp_no.equals("ALL"))
{
sql+=" and hh_pn in(select hh_pn from r_user_model_t where user_id='"emp_no"')";
}
sql+=" group by hh_pn";
rs2=stmt2.executeQuery(sql);
while(rs2.next())
{
String hh_tmp = rs2.getString(1);
product_before.put(hh_tmp,rs2.getString(2));
delivery_before.put(hh_tmp,rs2.getString(3));
sc_in_before.put(hh_tmp,rs2.getString(4));
sc_out_before.put(hh_tmp,rs2.getString(5));
balance_qty_before.put(hh_tmp,rs2.getString(6));
}
sql="select hh_pn,sum(product_req),sum(c_delivery),sum(sc_in),sum(sc_out) "+
"from v_new_balance_t "+
"where version='"group"' "+
"and c_date['"first_date"' and hh_pn='"hh"'";
if(!emp_no.equals("ALL"))
{
sql+=" and hh_pn in(select hh_pn from r_user_model_t where user_id='"emp_no"')";
}
sql+=" group by hh_pn";

rs2=stmt2.executeQuery(sql);
while(rs2.next())
{
String hhpn = rs2.getString(1);
product_cum_before.put(hhpn,rs2.getString(2));
delivery_cum_before.put(hhpn,rs2.getString(3));
sc_in_cum_before.put(hhpn,rs2.getString(4));
sc_out_cum_before.put(hhpn,rs2.getString(5));
}
%>
tr

<%=doc.getShow(hh)%>[/div]
[/td]
<%=doc.getShow(rs.getString(2))%>[/div]
[/td]
td nowrap
<%=model0%>[/div]
[/td]
td nowrap
[/div]
[/td]
<%
for(i=0;i[date_array.length;i++)
{
%>
td nowrap

<%
today=doc.getDateValue(String.valueOf(date_array[i]));
quantitytemp=Long.parseLong(doc.getNum((String)required_quantity.get(hh+model0+today)));
if(quantitytemp!=0){
out.println(quantitytemp);
}else{
out.println(" ");
}
%>[/div]
[/td]
<%}%>
[/tr]
<%
for(int m=1;m[modelcount;m++)
{
%>
tr
td nowrap
<%=model.get(m)%>[/div]
[/td]
td nowrap
[/div]
[/td]
<%
for(i=0;i[date_array.length;i++){
%>
td nowrap

<%
today=doc.getDateValue(String.valueOf(date_array[i]));
quantitytemp=Long.parseLong(doc.getNum((String)required_quantity.get(hh+(String)model.get(m)+today)));
if(quantitytemp!=0)
{
out.println(quantitytemp);
}else
{
out.println(" ");
}
%>[/div]
[/td]
<%}%>
[/tr]
<%
}
%>
tr
td nowrap
Production Plan TTL[/div]
[/td]
td nowrap
[/div]
[/td]
<%
productcum=Long.parseLong(doc.getNum((String)product_before.get(hh)))+Long.parseLong(doc.getNum((String)product_cum_before.get(hh)));
for(i=0;i[date_array.length;i++)
{
%>
td nowrap

<%
today=doc.getDateValue(String.valueOf(date_array[i]));
quantitytemp=Long.parseLong(doc.getNum((String)product_req.get(hh+today)));
if(quantitytemp!=0)
{
out.println(quantitytemp);
}
else
{
out.println(" ");
}
productcum+=quantitytemp;
product_cum[i]=productcum;
%>[/div]
[/td]
<%}%>
[/tr]
tr
td nowrap
Production Plan Accumulation[/div]
[/td]
td nowrap
<%=Long.parseLong(doc.getNum((String)product_before.get(hh)))+Long.parseLong(doc.getNum((String)product_cum_before.get(hh)))%>[/div]
[/td]
<%
for(i=0;i[date_array.length;i++)
{
%>
td nowrap
<%=product_cum[i]%>[/div]
[/td]
<%}%>
[/tr]
tr
td nowrap
Additional Requirement[/div]
[/td]
td nowrap
[/div]
[/td]
<%
for(i=0;i[date_array.length;i++)
{
%>
td nowrap

<%
today=doc.getDateValue(String.valueOf(date_array[i]));
quantitytemp=Long.parseLong(doc.getNum((String)additional_req.get(hh+today)));
if(quantitytemp!=0)
{
out.println(quantitytemp);
}
else
{
out.println(" ");
}
%>[/div]
[/td]
<%}%>
[/tr]
tr
td nowrap
Actual Delivery[/div]
[/td]
td nowrap
[/div]
[/td]
<%
deliverycum=Long.parseLong(doc.getNum((String)delivery_before.get(hh)))+Long.parseLong(doc.getNum((String)delivery_cum_before.get(hh)));
for(i=0;i[date_array.length;i++)
{
%>
td nowrap

<%
today=doc.getDateValue(String.valueOf(date_array[i]));
quantitytemp=Long.parseLong(doc.getNum((String)c_delivery.get(hh+today)));
if(!SqlProcess.compareLimitTime(limit_date,date_array[i])){
if(quantitytemp!=0)
{
out.println(quantitytemp);
}
else
{
out.println(" ");
}
}else{
out.println(" ");
}
deliverycum+=quantitytemp;
delivery_cum[i]=deliverycum;
%>[/div]
[/td]
<%}%>
[/tr]
tr
td nowrap
Delivery Plan[/div]
[/td]
td nowrap
[/div]
[/td]
<%
for(i=0;i[date_array.length;i++)
{
%>
td nowrap

<%
today=doc.getDateValue(String.valueOf(date_array[i]));
quantitytemp=Long.parseLong(doc.getNum((String)delivery_plan.get(hh+today)));
if(SqlProcess.compareLimitTime(limit_date,date_array[i])){
if(quantitytemp!=0){
out.println(quantitytemp);
}else{
out.println(" ");
}
}else{
out.println(" ");
}
%>[/div]
[/td]
<%}%>
[/tr]
tr
td nowrap
Delivery Accumulation[/div]
[/td]
td nowrap
<%=Long.parseLong(doc.getNum((String)delivery_before.get(hh)))+Long.parseLong(doc.getNum((String)delivery_cum_before.get(hh)))%>[/div]
[/td]
<%
for(i=0;i[date_array.length;i++)
{
%>
td nowrap
<%=delivery_cum[i]%>[/div]
[/td]
<%}%>
[/tr]
tr
td nowrap
Second Source IN[/div]
[/td]
td nowrap
<%=Long.parseLong(doc.getNum((String)sc_in_before.get(hh)))+Long.parseLong(doc.getNum((String)sc_in_cum_before.get(hh)))%>[/div]
[/td]
<%
for(i=0;i[date_array.length;i++)
{
%>
td nowrap

<%
today=doc.getDateValue(String.valueOf(date_array[i]));
quantitytemp=Long.parseLong(doc.getNum((String)sc_in.get(hh+today)));
if(quantitytemp!=0){
out.println(quantitytemp);
}else{
out.println(" ");
}
%>[/div]
[/td]
<%}%>
[/tr]
tr
td nowrap
Second Source OUT[/div]
[/td]
td nowrap
<%=Long.parseLong(doc.getNum((String)sc_out_before.get(hh)))+Long.parseLong(doc.getNum((String)sc_out_cum_before.get(hh)))%>[/div]
[/td]
<%
for(i=0;i[date_array.length;i++)
{
%>
td nowrap

<%
today=doc.getDateValue(String.valueOf(date_array[i]));
quantitytemp=Long.parseLong(doc.getNum((String)sc_out.get(hh+today)));
if(quantitytemp!=0){
out.println(quantitytemp);
}else{
out.println(" ");
}
%>[/div]
[/td]
<%}%>
[/tr]
tr
td nowrap
Balance[/div]
[/td]
td nowrap
<%=doc.getNum((String)balance_qty_before.get(rs.getString(1)))%>[/div]
[/td]
<%
for(i=0;i[date_array.length;i++)
{
%>
td nowrap

<%
today=doc.getDateValue(String.valueOf(date_array[i]));
quantitytemp=Long.parseLong(doc.getNum((String)c_balance.get(hh+today)));
if(quantitytemp!=0){
out.println(quantitytemp);
}else{
out.println(" ");
}
%>[/div]
[/td]
<%}%>
[/tr]
tr
td nowrap
Tiptop Stock[/div]
[/td]
td nowrap
[/div]
[/td]
<%
for(i=0;i[date_array.length;i++)
{
%>
td nowrap
<%
today=doc.getDateValue(String.valueOf(date_array[i]));
quantitytemp=Long.parseLong(doc.getNum((String)tiptop_stock.get(hh+today)));
if(quantitytemp!=0){
out.println(quantitytemp);
}else{
out.println(" ");
}
%>[/div]
[/td]
<%}%>
[/tr]
<%
}rs.close();
%>
[/table]
[/td]
[/tr]
[/table]
<%@ include file="../global/freeconnection.inc"%>
Updated on 2007-06-07T17:32:07Z at 2007-06-07T17:32:07Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    210 Posts
    ACCEPTED ANSWER

    Re: a inefficient JSP page, too much time need to wait

    ‏2007-06-07T06:10:24Z  in response to SystemAdmin
    Because the tag[],some places replaced wrongly.The below corrected:

    <%@ taglib uri="/bean" prefix="bean"%>
    <%@ taglib uri="/html" prefix="html"%>
    <%@ page import="com.actual.inventory.*" contentType="text/html;charset=big5"%>
    <%@ page import="com.rover.*"%>

    <%@ include file="../global/connection.inc"%>
    <%
    String group=doc.getUTF(request.getParameter("group"));
    String emp_no=doc.getUTF(request.getParameter("emp_no"));
    java.sql.Date limit_date=SqlProcess.getLimitTime(conn);
    long quantitytemp=0;
    String today="";
    String from_date="20070312";
    String to_date="";
    /*
    sql="select to_char(sysdate-56,'yyyymmdd') from dual";
    rs=stmt.executeQuery(sql);
    if(rs.first()){
    from_date=doc.getPost(rs.getString(1));
    }rs.close();
    */
    sql="select max(c_date) from v_new_balance_t";
    rs=stmt.executeQuery(sql);
    if(rs.first()){
    to_date=doc.getPost(rs.getString(1));
    }rs.close();
    int i=0;
    String user_id=request.getRemoteUser();
    String user_name="";
    sql="SELECT C_NAME FROM C_USER_T WHERE C_ID='"WC.htmlEncode(user_id)"'";
    rs=stmt.executeQuery(sql);
    if(rs.first()){
    user_name=doc.getPost(rs.getString(1));
    }rs.close();
    Phase phase=new Phase();
    FormatWeek FW=new FormatWeek();
    GetMonday GM=new GetMonday();
    GetSunday GS=new GetSunday();
    String first_week=FW.getWeekNum(FW.getweek(from_date));
    String last_week=FW.getWeekNum(FW.getweek(to_date));
    String first_date=GM.getmonday(first_week.substring(0,4),first_week.substring(4,6));
    String last_date=GS.getsunday(last_week.substring(0,4),last_week.substring(4,6));
    java.sql.Datehttp://] date_array=(java.sql.Date[)((ArrayList)phase.getPhase(doc.getDate(first_date),doc.getDate(last_date))).toArray(new java.sql.Date[0]);
    String] week_array=(String[)((ArrayList)phase.getFormatWeekPhase(first_week,last_week)).toArray(new String[0]);
    String[] week_count_array=new Stringhttp://week_array.length;
    for(i=0;i[week_array.length;i++)
    {
    week_count_array=String.valueOf(phase.getWeekCount(week_array));
    }
    String[] date_week_array=new Stringhttp://date_array.length;
    for(i=0;i[date_array.length;i++)
    {
    date_week_array=FW.getWeekNum(FW.getweek(doc.getDateValue(String.valueOf(date_array))));
    }
    /* Total? */
    long productcum=0;
    long deliverycum=0;
    long[] product_cum=new longhttp://date_array.length;
    long[] delivery_cum=new longhttp://date_array.length;
    //HashMap hh_pn = new HashMap();
    HashMap product_req=new HashMap();
    HashMap additional_req=new HashMap();
    HashMap c_delivery=new HashMap();
    HashMap sc_in=new HashMap();
    HashMap sc_out=new HashMap();
    HashMap c_balance=new HashMap();
    HashMap tiptop_stock=new HashMap();

    //before
    HashMap product_before=new HashMap();
    HashMap delivery_before=new HashMap();
    HashMap sc_in_before=new HashMap();
    HashMap sc_out_before=new HashMap();
    HashMap balance_qty_before=new HashMap();

    //Accumulation before
    HashMap product_cum_before=new HashMap();
    HashMap delivery_cum_before=new HashMap();
    HashMap sc_in_cum_before=new HashMap();
    HashMap sc_out_cum_before=new HashMap();
    %>

    tr
    td
    : <%=first_date.substring(0,4)+"/"first_date.substring(4,6)"/"first_date.substring(6,8)%> - <%=last_date.substring(0,4)"/"last_date.substring(4,6)"/"+last_date.substring(6,8)%>[/div]
    [/td]
    [/tr]
    tr
    td
    : <%=user_name%>[/div]
    [/td]
    [/tr]
    tr
    td
    : <%=SqlProcess.getSystemTimestamp(conn)%>[/div]
    [/td]
    [/tr]
    tr
    td

    tr

    HH P/N[/div]
    [/td]
    [!--
    ---------------SONY P/N[/div]
    [/td] --]

    Description[/div]
    [/td]

    Item[/div]
    [/td]

    Before[/div]
    [/td]
    <%
    for(i=0;i[week_array.length;i++)
    {
    %>

    <%=doc.getShow(week_array.substring(0,4)+"Y . "week_array.substring(4,6)"W")%>[/div]
    [/td]
    <%}%>
    [/tr]
    tr
    <%
    for(i=0;i[date_array.length;i++)
    {
    %>
    td nowrap
    <%=doc.getShow(phase.getWeekName(date_array))%>[/div]
    [/td]
    <%}%>
    [/tr]
    tr
    <%
    for(i=0;i[date_array.length;i++)
    {
    %>
    td nowrap
    <%=doc.getShow(String.valueOf(date_array).substring(5,10).replaceAll("-", "/"))%>[/div]
    [/td]
    <%}%>
    [/tr]
    <%
    sql="select distinct v.hh_pn,v.hh_description "+
    "from v_new_balance_t a,v_item_info_t v "+
    "where a.hh_pn=v.hh_pn and a.version='"group"'";
    if(!emp_no.equals("ALL"))
    {
    sql+=" and v.hh_pn in(select hh_pn from r_user_model_t where user_id='"emp_no"')";
    }
    sql+=" and a.c_date>='"first_date"' and a.c_date<='"last_date"'";

    rs=stmt.executeQuery(sql);
    while(rs.next()){
    String hh = rs.getString(1);
    int modelcount=0;
    Vector model=new Vector();
    sql2="select a.child_pn,substr(v.customer_code,0,4) "+
    "from v_kp_prq_t a,v_vpn_t@no_consign.foxconn.com v "+
    "where a.hh_pn=v.hh_pn";
    if(group.equals("ON_THE_NB"))
    {
    sql2+=" and v.hh_pn in(select hh_pn from v_vpn_t@no_consign.foxconn.com where trade_model is null and customer_code in(select customer_name from c_customer_group_t@no_consign.foxconn.com where group_name='NB'))";
    }
    if(group.equals("ON_THE_DH"))
    {
    sql2+=" and v.hh_pn in(select hh_pn from v_vpn_t@no_consign.foxconn.com where trade_model is null and customer_code in(select customer_name from c_customer_group_t@no_consign.foxconn.com where group_name='DH'))";
    }
    if(group.equals("ON_THE_CSCM"))
    {
    sql2+=" and v.hh_pn in(select hh_pn from v_vpn_t@no_consign.foxconn.com where trade_model='CN')";
    }
    sql2+=" and a.child_pn='"hh"'";
    sql2+=" and a.required_date>='"first_date"' and a.required_date<='"last_date"'";
    //out.println("");
    rs2=stmt2.executeQuery(sql2);
    while(rs2.next())
    {
    String item_num_tmp = rs2.getString(2);
    if(!model.contains(item_num_tmp))
    {
    model.add(item_num_tmp);
    modelcount+=1;
    }
    }
    rs2.close();
    HashMap required_quantity=new HashMap();
    sql2="select a.child_pn,substr(v.customer_code,0,4),required_date,sum(required_quantity) "+
    "from v_kp_prq_t a,v_vpn_t@no_consign.foxconn.com v "+
    "where a.hh_pn=v.hh_pn";
    if(group.equals("ON_THE_NB"))
    {
    sql2+=" and v.hh_pn in(select hh_pn from v_vpn_t@no_consign.foxconn.com where trade_model is null and customer_code in(select customer_name from c_customer_group_t@no_consign.foxconn.com where group_name='NB'))";
    }
    if(group.equals("ON_THE_DH"))
    {
    sql2+=" and v.hh_pn in(select hh_pn from v_vpn_t@no_consign.foxconn.com where trade_model is null and customer_code in(select customer_name from c_customer_group_t@no_consign.foxconn.com where group_name='DH'))";
    }
    if(group.equals("ON_THE_CSCM"))
    {
    sql2+=" and v.hh_pn in(select hh_pn from v_vpn_t@no_consign.foxconn.com where trade_model='CN')";
    }
    sql2+=" and a.child_pn='"hh"'"+
    " and a.required_date>='"first_date"' and a.required_date<='"last_date"' "+
    " group by a.child_pn,substr(v.customer_code,0,4),required_date";
    rs2=stmt2.executeQuery(sql2);
    while(rs2.next())
    {
    required_quantity.put(rs2.getString(1)+rs2.getString(2)+rs2.getString(3),rs2.getString(4));
    }
    rs2.close();
    String model0=" ";
    if(model.size()!=0)
    {
    model0=(String)model.get(0);
    }
    if(modelcount==0)
    {
    modelcount=1;
    }

    sql="select hh_pn,c_date,product_req,additional_req,c_delivery,c_balance "+
    "from v_new_balance_t "+
    "where version='"group"' "+
    "and c_date>='"first_date"' and c_date<='"last_date"' and hh_pn='"hh"'";
    if(!emp_no.equals("ALL"))
    {
    sql+=" and hh_pn in(select hh_pn from r_user_model_t where user_id='"emp_no"')";
    }
    rs2=stmt2.executeQuery(sql);
    Get_qrt get_qrt = new Get_qrt();
    while(rs2.next())
    {
    String hh_pn_tmp = doc.getPost(rs2.getString(1));
    String c_date_tmp = doc.getPost(rs2.getString(2));
    product_req.put(hh_pn_tmp+c_date_tmp,rs2.getString(3));
    additional_req.put(hh_pn_tmp+c_date_tmp,rs2.getString(4));
    c_delivery.put(hh_pn_tmp+c_date_tmp,rs2.getString(5));
    c_balance.put(hh_pn_tmp+c_date_tmp,rs2.getString("c_balance"));

    get_qrt.get_stmt(conn);
    String sql_sc_in = "select quantity from r_replace_online_t where master_kp='"hh_pn_tmp"' and work_date = '"c_date_tmp"' and version='"group"'";
    get_qrt.get_qrt(sql_sc_in,sc_in,hh_pn_tmp,c_date_tmp);
    String sql_sc_out = "select quantity from r_replace_online_t where replace_kp='"hh_pn_tmp"' and work_date = '"c_date_tmp"' and version='"group"'";
    get_qrt.get_qrt(sql_sc_out,sc_out,hh_pn_tmp,c_date_tmp);
    String sql_tiptop_stock = "select quantity from data_from_tiptop where hh_pn='"hh_pn_tmp"' and the_date = '"c_date_tmp"' and version='"group"'";
    get_qrt.get_qrt(sql_tiptop_stock,tiptop_stock,hh_pn_tmp,c_date_tmp);
    get_qrt.close();
    }

    //Delivery Plan
    HashMap delivery_plan=new HashMap();
    sql="select hh_pn,delivery_date,quantity "+
    "from v_delivery_plan_t "+
    "where version='"group"' "+
    "and delivery_date>='"first_date"' and delivery_date<='"last_date"' and hh_pn='"hh"'";
    if(!emp_no.equals("ALL"))
    {
    sql+=" and hh_pn in(select hh_pn from r_user_model_t where user_id='"emp_no"')";
    }

    rs2=stmt2.executeQuery(sql);
    while(rs2.next())
    {
    delivery_plan.put(rs2.getString(1)+rs2.getString(2),rs2.getString(3));
    }

    sql="select hh_pn,sum(pp_accum_qty),sum(delivery_accum_qty),sum(sc_in),sum(sc_out),sum(balance_qty) "+
    "from v_balance_before_t where version='"group"' and hh_pn='"hh"'";
    if(!emp_no.equals("ALL"))
    {
    sql+=" and hh_pn in(select hh_pn from r_user_model_t where user_id='"emp_no"')";
    }
    sql+=" group by hh_pn";
    rs2=stmt2.executeQuery(sql);
    while(rs2.next())
    {
    String hh_tmp = rs2.getString(1);
    product_before.put(hh_tmp,rs2.getString(2));
    delivery_before.put(hh_tmp,rs2.getString(3));
    sc_in_before.put(hh_tmp,rs2.getString(4));
    sc_out_before.put(hh_tmp,rs2.getString(5));
    balance_qty_before.put(hh_tmp,rs2.getString(6));
    }
    sql="select hh_pn,sum(product_req),sum(c_delivery),sum(sc_in),sum(sc_out) "+
    "from v_new_balance_t "+
    "where version='"group"' "+
    "and c_date>'"first_date"' and hh_pn='"hh"'";
    if(!emp_no.equals("ALL"))
    {
    sql+=" and hh_pn in(select hh_pn from r_user_model_t where user_id='"emp_no"')";
    }
    sql+=" group by hh_pn";

    rs2=stmt2.executeQuery(sql);
    while(rs2.next())
    {
    String hhpn = rs2.getString(1);
    product_cum_before.put(hhpn,rs2.getString(2));
    delivery_cum_before.put(hhpn,rs2.getString(3));
    sc_in_cum_before.put(hhpn,rs2.getString(4));
    sc_out_cum_before.put(hhpn,rs2.getString(5));
    }
    %>
    tr

    <%=doc.getShow(hh)%>[/div]
    [/td]
    <%=doc.getShow(rs.getString(2))%>[/div]
    [/td]
    td nowrap
    <%=model0%>[/div]
    [/td]
    td nowrap
    [/div]
    [/td]
    <%
    for(i=0;i[date_array.length;i++)
    {
    %>
    td nowrap

    <%
    today=doc.getDateValue(String.valueOf(date_array));
    quantitytemp=Long.parseLong(doc.getNum((String)required_quantity.get(hh+model0+today)));
    if(quantitytemp!=0){
    out.println(quantitytemp);
    }else{
    out.println(" ");
    }
    %>[/div]
    [/td]
    <%}%>
    [/tr]
    <%
    for(int m=1;m[modelcount;m++)
    {
    %>
    tr
    td nowrap
    <%=model.get(m)%>[/div]
    [/td]
    td nowrap
    [/div]
    [/td]
    <%
    for(i=0;i<date_array.length;i++){
    %>
    td nowrap

    <%
    today=doc.getDateValue(String.valueOf(date_array));
    quantitytemp=Long.parseLong(doc.getNum((String)required_quantity.get(hh+(String)model.get(m)+today)));
    if(quantitytemp!=0)
    {
    out.println(quantitytemp);
    }else
    {
    out.println(" ");
    }
    %>[/div]
    [/td]
    <%}%>
    [/tr]
    <%
    }
    %>
    tr
    td nowrap
    Production Plan TTL[/div]
    [/td]
    td nowrap
    [/div]
    [/td]
    <%
    productcum=Long.parseLong(doc.getNum((String)product_before.get(hh)))+Long.parseLong(doc.getNum((String)product_cum_before.get(hh)));
    for(i=0;i<date_array.length;i++)
    {
    %>
    td nowrap

    <%
    today=doc.getDateValue(String.valueOf(date_array));
    quantitytemp=Long.parseLong(doc.getNum((String)product_req.get(hh+today)));
    if(quantitytemp!=0)
    {
    out.println(quantitytemp);
    }
    else
    {
    out.println(" ");
    }
    productcum+=quantitytemp;
    product_cum=productcum;
    %>[/div]
    [/td]
    <%}%>
    [/tr]
    tr
    td nowrap
    Production Plan Accumulation[/div]
    [/td]
    td nowrap
    <%=Long.parseLong(doc.getNum((String)product_before.get(hh)))+Long.parseLong(doc.getNum((String)product_cum_before.get(hh)))%>[/div]
    [/td]
    <%
    for(i=0;i[date_array.length;i++)
    {
    %>
    td nowrap
    <%=product_cum%>[/div]
    [/td]
    <%}%>
    [/tr]
    tr
    td nowrap
    Additional Requirement[/div]
    [/td]
    td nowrap
    [/div]
    [/td]
    <%
    for(i=0;i[date_array.length;i++)
    {
    %>
    td nowrap

    <%
    today=doc.getDateValue(String.valueOf(date_array));
    quantitytemp=Long.parseLong(doc.getNum((String)additional_req.get(hh+today)));
    if(quantitytemp!=0)
    {
    out.println(quantitytemp);
    }
    else
    {
    out.println(" ");
    }
    %>[/div]
    [/td]
    <%}%>
    [/tr]
    tr
    td nowrap
    Actual Delivery[/div]
    [/td]
    td nowrap
    [/div]
    [/td]
    <%
    deliverycum=Long.parseLong(doc.getNum((String)delivery_before.get(hh)))+Long.parseLong(doc.getNum((String)delivery_cum_before.get(hh)));
    for(i=0;i[date_array.length;i++)
    {
    %>
    td nowrap

    <%
    today=doc.getDateValue(String.valueOf(date_array));
    quantitytemp=Long.parseLong(doc.getNum((String)c_delivery.get(hh+today)));
    if(!SqlProcess.compareLimitTime(limit_date,date_array)){
    if(quantitytemp!=0)
    {
    out.println(quantitytemp);
    }
    else
    {
    out.println(" ");
    }
    }else{
    out.println(" ");
    }
    deliverycum+=quantitytemp;
    delivery_cum=deliverycum;
    %>[/div]
    [/td]
    <%}%>
    [/tr]
    tr
    td nowrap
    Delivery Plan[/div]
    [/td]
    td nowrap
    [/div]
    [/td]
    <%
    for(i=0;i[date_array.length;i++)
    {
    %>
    td nowrap

    <%
    today=doc.getDateValue(String.valueOf(date_array));
    quantitytemp=Long.parseLong(doc.getNum((String)delivery_plan.get(hh+today)));
    if(SqlProcess.compareLimitTime(limit_date,date_array)){
    if(quantitytemp!=0){
    out.println(quantitytemp);
    }else{
    out.println(" ");
    }
    }else{
    out.println(" ");
    }
    %>[/div]
    [/td]
    <%}%>
    [/tr]
    tr
    td nowrap
    Delivery Accumulation[/div]
    [/td]
    td nowrap
    <%=Long.parseLong(doc.getNum((String)delivery_before.get(hh)))+Long.parseLong(doc.getNum((String)delivery_cum_before.get(hh)))%>[/div]
    [/td]
    <%
    for(i=0;i[date_array.length;i++)
    {
    %>
    td nowrap
    <%=delivery_cum%>[/div]
    [/td]
    <%}%>
    [/tr]
    tr
    td nowrap
    Second Source IN[/div]
    [/td]
    td nowrap
    <%=Long.parseLong(doc.getNum((String)sc_in_before.get(hh)))+Long.parseLong(doc.getNum((String)sc_in_cum_before.get(hh)))%>[/div]
    [/td]
    <%
    for(i=0;i[date_array.length;i++)
    {
    %>
    td nowrap

    <%
    today=doc.getDateValue(String.valueOf(date_array));
    quantitytemp=Long.parseLong(doc.getNum((String)sc_in.get(hh+today)));
    if(quantitytemp!=0){
    out.println(quantitytemp);
    }else{
    out.println(" ");
    }
    %>[/div]
    [/td]
    <%}%>
    [/tr]
    tr
    td nowrap
    Second Source OUT[/div]
    [/td]
    td nowrap
    <%=Long.parseLong(doc.getNum((String)sc_out_before.get(hh)))+Long.parseLong(doc.getNum((String)sc_out_cum_before.get(hh)))%>[/div]
    [/td]
    <%
    for(i=0;i[date_array.length;i++)
    {
    %>
    td nowrap

    <%
    today=doc.getDateValue(String.valueOf(date_array));
    quantitytemp=Long.parseLong(doc.getNum((String)sc_out.get(hh+today)));
    if(quantitytemp!=0){
    out.println(quantitytemp);
    }else{
    out.println(" ");
    }
    %>[/div]
    [/td]
    <%}%>
    [/tr]
    tr
    td nowrap
    Balance[/div]
    [/td]
    td nowrap
    <%=doc.getNum((String)balance_qty_before.get(rs.getString(1)))%>[/div]
    [/td]
    <%
    for(i=0;i[date_array.length;i++)
    {
    %>
    td nowrap

    <%
    today=doc.getDateValue(String.valueOf(date_array));
    quantitytemp=Long.parseLong(doc.getNum((String)c_balance.get(hh+today)));
    if(quantitytemp!=0){
    out.println(quantitytemp);
    }else{
    out.println(" ");
    }
    %>[/div]
    [/td]
    <%}%>
    [/tr]
    tr
    td nowrap
    Tiptop Stock[/div]
    [/td]
    td nowrap
    [/div]
    [/td]
    <%
    for(i=0;i[date_array.length;i++)
    {
    %>
    td nowrap
    <%
    today=doc.getDateValue(String.valueOf(date_array));
    quantitytemp=Long.parseLong(doc.getNum((String)tiptop_stock.get(hh+today)));
    if(quantitytemp!=0){
    out.println(quantitytemp);
    }else{
    out.println(" ");
    }
    %>[/div]
    [/td]
    <%}%>
    [/tr]
    <%
    }rs.close();
    %>
    [/table]
    [/td]
    [/tr]
    [/table]
    <%@ include file="../global/freeconnection.inc"%>
    • SystemAdmin
      SystemAdmin
      210 Posts
      ACCEPTED ANSWER

      Re: a inefficient JSP page, too much time need to wait

      ‏2007-06-07T17:32:07Z  in response to SystemAdmin
      This page is doing quite a lot, which presents a number of options to consider if you're seeking assistance in speeding it up. Casually looking at it, you're communicating with a database and using a whole lot of maps-- and that's just the first few lines of code. It would be hard to guess without real numbers what is your biggest bang for the buck, but I'd start by refactoring as much of this code out of a JSP and into POJOs that you can isolate and then test for efficiency. By breaking the code up you'll be better suited to isolate performance issues (whether they be IO, algorithms, etc is purely speculation at this point with so much code to evaluate in one file, but I'd bet your performance issues are db related) Then you can start to work on performance issues...

      You could also run a profiler at the resulting servlet and see if you can spot the culprit (assuming it is just one thing...).