Friday, May 21, 2010

How to install and configure Sun's Jdk in Fedora 11

Visit http://java.sun.com/javase/downloads/widget/jdk6.jsp to download the jdk. While downloading select "jdk-6u20-linux-i586-rpm.bin".
Once downloading is finished login using root privileges and run the following:
#chmod 777 jdk-6u20-linux-i586-rpm.bin
#./ jdk-6u20-linux-i586-rpm.bin

This will start extraction of various packages in the file and the start installing it. Accept the license agreement.

If you already have open jdk installed on your machine, then to use the new jdk you need to change the links pointed by /usr/bin/java*. Following lines shows it how to do that: (# prompt means root's shell)
#ln -fs /usr/java/jdk1.6.0_20/bin/java /usr/bin/java
After changing the link you can check the version using
$java -version
Similarly we need to change the link for javac, javadoc, javah, javap, javaw
#ln -fs /usr/java/jdk1.6.0_20/bin/javac /usr/bin/javac
#ln -fs /usr/java/jdk1.6.0_20/bin/javadoc /usr/bin/javadoc
#ln -fs /usr/java/jdk1.6.0_20/bin/javah /usr/bin/javah
ln -fs /usr/java/jdk1.6.0_20/bin/javap /usr/bin/javap
ln -fs /usr/java/jdk1.6.0_20/bin/javaws /usr/bin/javaws

Check all the paths using
#ls -l /usr/bin/java*

Wednesday, May 12, 2010

Threading in linux

Following is the simple program which creates 2 new threads. It uses pthread library.  To compile use
"gcc filename.c -pthread"

#include
#include
#include

void * run (void * usearg)
{
    int *count;
    struct timespec sleepTime;
    struct timespec remainingSleepTime;
   
    count = (int *)usearg;
    printf("In child:%d\n",*count);
    while(*count <20000)
    {
        printf("%d\t",*count);
        (*count)++;
        sleepTime.tv_sec=0;
        sleepTime.tv_nsec=100;
        nanosleep(&sleepTime,&remainingSleepTime);
    }
    printf("Child thread finished\n");
    return NULL;
}

void * runAnother (void * usearg)
{
    int *count;
    struct timespec sleepTime;
    struct timespec remainingSleepTime;
   
    count = (int *)usearg;
    printf("In child:%d\n",*count);
    while(*count <30000)
    {
        printf("%d\t",*count);
        (*count)++;
        sleepTime.tv_sec=0;
        sleepTime.tv_nsec=100;
        nanosleep(&sleepTime,&remainingSleepTime);
    }
    printf("Child thread finished\n");
    return NULL;
}

int main()
{
    void *retValue;
    pthread_t threadId,threadId1;
    int countThread = 10000,countThread1 = 20000;
    int countMain = 0;
    struct timespec sleepTime;
    struct timespec remainingSleepTime;

    if(pthread_create(&threadId,NULL,run, &countThread)==0 && pthread_create(&threadId1,NULL,runAnother, &countThread1)==0)
    {
        printf("Thread created sucessfully\n");
    }
    else
    {
        perror("Thread could not be created\n");
    }
    while(countMain<10000)
    {
        printf("%d\t",countMain);
        countMain++;
        sleepTime.tv_sec=0;
        sleepTime.tv_nsec=100;
        nanosleep(&sleepTime,&remainingSleepTime);
    }
    printf("Main thread finished\n");
    pthread_join(threadId,&retValue);
    pthread_join(threadId1,&retValue);
    printf("Children Joined\n");
    return 0;
}

Android aar deployment in Maven - 2022

Introduction If you are working on android library project, you might be wondering how to publish it on Maven like this . Earl...