entroducing.com
  • Home
  • Coding
  • Trading
  • Troubleshooting
    • Operating System
    • Networking
  • Reviews
  • Travel
  • Quick Snap
  • Thoughts
  • Side Hustle
  • Earn Passive Income/Referral
Website sponsored by LingeriesG
@2023 - All Right Reserved. Entroducing. Sponsored by mm3288
Codingjava

Printing out active threads in java

by Ben February 20, 2010
written by Ben

Here’s the code snippets to display the number of running threads in your java program.

It’s good to use it to track your resources.

int activeCount = Thread.activeCount();
System.out.println("total active = " + activeCount);
Thread[] threads = new Thread[activeCount];
Thread.enumerate(threads);

System.out.println("before");
for (int j=0; j<threads.length; j++) {
 System.out.println(threads[j].toString());
}

//run your classes
Benny benny = new Benny();

activeCount = Thread.activeCount();
System.out.println("total active = " + activeCount);

threads = new Thread[activeCount];
System.out.println("after");
Thread.enumerate(threads);
for (int i=0; i<threads.length; i++) {
 System.out.println(threads[i].toString());
}

February 20, 2010 0 comment
0 FacebookTwitterPinterestEmail
CodingSQL

Using single SQL query to retrieve counts of two subqueries

by Ben January 23, 2010
written by Ben

Recently received a question from someone asking for a single SQL statement to retrieve the counts for two subqueries (or something like that).

I had altered the question and and my answer below.

A company has several customers and courses. Each customer may be signing up on several courses.
Write an SQL query to display the number of women and the number of men signing on each course.

And my simple database design

CREATE TABLE `CUSTOMER` (
`CUSTOMER_ID` INT NULL AUTO_INCREMENT PRIMARY KEY,
`NAME` VARCHAR( 100 ) NULL ,
`GENDER` CHAR( 1 ) NULL ,
`EMAIL` VARCHAR( 150 ) NULL
) ENGINE = MYISAM ;

CREATE TABLE `COURSE` (
`COURSE_ID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`NAME` VARCHAR( 50 ) NOT NULL ,
`DESCRIPTION` VARCHAR( 255 ) NOT NULL ,
`START_DATE` DATE NOT NULL ,
`END_DATE` DATE NOT NULL
PRIMARY KEY ( `COURSE_ID` )
) ENGINE = MYISAM ;

CREATE TABLE `CUSTOMER_COURSE` (
`CUSTOMER_ID` INT NULL ,
`COURSE_ID` INT NULL ,
`STATUS` VARCHAR( 5 ) NULL
) ENGINE = MYISAM ;

And the SQL to “display the number of women and the number of men signing on each course”

select
    sum(total_males) as total_males,
    sum(total_females) as total_females,
    COURSE_id
from
    (select COUNT(e.GENDER) as total_males , 0 as total_females, ep.COURSE_ID
        from CUSTOMER e, CUSTOMER_COURSE ep
        where ep.CUSTOMER_ID = e.CUSTOMER_ID and e.GENDER = 'M'
        group by ep.COURSE_ID
    union all
    select 0 as total_males, COUNT(e.GENDER) as total_females ,ep.COURSE_ID
        from CUSTOMER e, CUSTOMER_COURSE ep
        where ep.CUSTOMER_ID = e.CUSTOMER_ID and e.GENDER = 'F'
    group by ep.COURSE_ID
	) t1
group by COURSE_id

Explanation:

  • the two subqueries generate 3 columns: total males, total females, course ID
  • one of the columns in the two subqueries is 0
  • the two subqueries would then UNION ALL to populate all results for the parent SQL
  • the parent SQL would then do a SUM/COUNT for the subqueries by grouping the course ID.
  • the ‘t1’ is just a empty table name thrown back to the parent for reference
January 23, 2010 0 comment
0 FacebookTwitterPinterestEmail
Codingjava

Making a Struts Radio selected

by Ben January 17, 2010
written by Ben

By default, struts’s html radio tag do not allow you to make a radio to be selected as they have no “selected” property or something

<html:radio property="gender" value="F" />Male
<html:radio property="gender" value="M"/>Female

To make a radio button to be selected on load, set the value that you want to be selected in your action form reset method


public void reset(ActionMapping mapping, HttpServletRequest request) {
            super.reset(mapping, request);
            gender= "F";
      }

January 17, 2010 0 comment
0 FacebookTwitterPinterestEmail
Thoughts

My nephew dropped his Macbook Pro

by Ben December 12, 2009
written by Ben

Sayang…

macbookpro_dropped (1)

macbookpro_dropped (2)

macbookpro_dropped (3)

December 12, 2009 2 comments
0 FacebookTwitterPinterestEmail
Codingphp

Array sorting problem posted from hardwarezone

by Ben November 22, 2009
written by Ben

Saw this challenging question posted in the hardwarezone forum on sorting an array with one for loop without using array list.

The question is


This is a simple programming question...very simple and short question, but its really hard to solve..
Anyone who could do it, you are god of programming. 

 Given an array of random numbers let say..

 arrayX = {15, 20, 35, 45, 10, 40, 1, 3, 45};You are supposed to use ONLY ONE loop to swap the above into the following:
 arrayX = {15, 20, 3, 1, 10, 40, 45, 35, 45};

 NOTE: The purpose of your loop is to move all digits < 25 from the right hand side to the left side, and move all digits >= 25 to the right side. You can't sort the array but to use a single loop to scan the array from left and scan the array from right...and do the necessary swapping.

 You can try do it with C, C++...etc..
 Not easy as it seems to be!

Since the night is still young, I took some time to sit down and figure out the solution.

Continue Reading
November 22, 2009 0 comment
0 FacebookTwitterPinterestEmail
Operating System

Unboxing Windows 7 Family Pack

by Ben November 12, 2009
written by Ben

Just received my Win 7 Family Pack from Amazon via VPost shipping.

Bought it at USD199 per pcs and SGD17+ for the shipping charges.

Im still backing up my files and will be installing Win7 over the weekend.

Here are the photos. Click on it to enlarge.

win7familyunbox00001

Hehe... Notice that it is USD1?

Continue Reading
November 12, 2009 0 comment
0 FacebookTwitterPinterestEmail
Quick Snap

bangkok night view

by Ben November 7, 2009
written by Ben

Taken @ bangkok baiyoke sky hotel

f2.8, iso1600, 1/4sec

bangkok city night

November 7, 2009 0 comment
0 FacebookTwitterPinterestEmail
Quick Snap

cross road

by Ben October 31, 2009
written by Ben

Taken in 2008 @ shanghai

cross road

October 31, 2009 0 comment
0 FacebookTwitterPinterestEmail
  • 1
  • …
  • 7
  • 8
  • 9
  • 10

Search

Categories

  • Coding
    • apache
    • cakephp
    • java
    • magento
    • php
    • SQL
    • symfony
    • wordpress
  • Hosting
  • Quick Snap
  • Reviews
  • Side Hustle
  • Thoughts
  • Trading
  • Travel
  • Troubleshooting
    • Networking
    • Operating System

Tags

3.28 angry bird jb angry birds activity park apache beijing cakephp cdata cruise crypto docker elasticsearch element mall fil ftx claim hacked hanshou how-to html data in xml java johor bahru jumper land linux mac magento magento2 malacca malaysia travel move-to-earn passive income php plugin Programming rides side hustle stepn stfil stfil.io struts SyntaxHighlighter theme travel VPS windows 7 wordpress xampp
  • Email

@2023 - All Right Reserved. Entroducing. Sponsored by mm3288