Tuesday, 23 September 2025

Wednesday, 10 September 2025

Runnable ,callable ,Executer service Thred example

 import java.util.concurrent.Callable;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class RunnableAndThread implements Runnable , Callable<Integer> {
@Override
public void run() {
System.out.println("hello");
}

public void myrun() {
System.out.println("hellopawan");
}
@Override
public Integer call() {
return 50;
}

public static void main(String args[]) throws ExecutionException, InterruptedException {
ExecutorService executor = Executors.newFixedThreadPool(3);
executor.submit((Runnable) new RunnableAndThread());
executor.submit(()->new RunnableAndThread().myrun());
Future<Integer> future = executor.submit((Callable<Integer>) new RunnableAndThread());
System.out.println("Callable result: " + future.get());
//Thread runnableAndThread = new Thread(()->new RunnableAndThread().myrun());
//runnableAndThread.start();
//Thread runnableAndThread1 = new Thread(new RunnableAndThread());
//runnableAndThread1.start();
}
}

Tuesday, 5 August 2025

Amazon SES RAW email

 https://docs.aws.amazon.com/ses/latest/dg/send-email-raw.html


package com.amazonaws.samples;


import java.io.ByteArrayOutputStream;

import java.io.IOException;

import java.io.PrintStream;

import java.nio.ByteBuffer;

import java.util.Properties;


// JavaMail libraries. Download the JavaMail API 

// from https://javaee.github.io/javamail/

import javax.activation.DataHandler;

import javax.activation.DataSource;

import javax.activation.FileDataSource;

import javax.mail.Message;

import javax.mail.MessagingException;

import javax.mail.Session;

import javax.mail.internet.AddressException;

import javax.mail.internet.InternetAddress;

import javax.mail.internet.MimeBodyPart;

import javax.mail.internet.MimeMessage;

import javax.mail.internet.MimeMultipart;


// AWS SDK libraries. Download the AWS SDK for Java 

// from https://aws.amazon.com/sdk-for-java

import com.amazonaws.regions.Regions;

import com.amazonaws.services.simpleemail.AmazonSimpleEmailService;

import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClientBuilder;

import com.amazonaws.services.simpleemail.model.RawMessage;

import com.amazonaws.services.simpleemail.model.SendRawEmailRequest;


public class AmazonSESSample {


// Replace sender@example.com with your "From" address.

// This address must be verified with Amazon SES.

private static String SENDER = "Sender Name <sender@example.com>";


// Replace recipient@example.com with a "To" address. If your account 

// is still in the sandbox, this address must be verified.

private static String RECIPIENT = "recipient@example.com";


// Specify a configuration set. If you do not want to use a configuration

// set, comment the following variable, and the 

// ConfigurationSetName=CONFIGURATION_SET argument below.

private static String CONFIGURATION_SET = "ConfigSet";


// The subject line for the email.

private static String SUBJECT = "Customer service contact info";


// The full path to the file that will be attached to the email.

// If you're using Windows, escape backslashes as shown in this variable.

private static String ATTACHMENT = "C:\\Users\\sender\\customers-to-contact.xlsx";


// The email body for recipients with non-HTML email clients.

private static String BODY_TEXT = "Hello,\r\n"

                                        + "Please see the attached file for a list "

                                        + "of customers to contact.";


// The HTML body of the email.

private static String BODY_HTML = "<html>"

                                        + "<head></head>"

                                        + "<body>"

                                        + "<h1>Hello!</h1>"

                                        + "<p>Please see the attached file for a "

                                        + "list of customers to contact.</p>"

                                        + "</body>"

                                        + "</html>";


    public static void main(String[] args) throws AddressException, MessagingException, IOException {

           

    Session session = Session.getDefaultInstance(new Properties());

        

        // Create a new MimeMessage object.

        MimeMessage message = new MimeMessage(session);

        

        // Add subject, from and to lines.

        message.setSubject(SUBJECT, "UTF-8");

        message.setFrom(new InternetAddress(SENDER));

        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(RECIPIENT));


        // Create a multipart/alternative child container.

        MimeMultipart msg_body = new MimeMultipart("alternative");

        

        // Create a wrapper for the HTML and text parts.        

        MimeBodyPart wrap = new MimeBodyPart();

        

        // Define the text part.

        MimeBodyPart textPart = new MimeBodyPart();

        textPart.setContent(BODY_TEXT, "text/plain; charset=UTF-8");

                

        // Define the HTML part.

        MimeBodyPart htmlPart = new MimeBodyPart();

        htmlPart.setContent(BODY_HTML,"text/html; charset=UTF-8");

                

        // Add the text and HTML parts to the child container.

        msg_body.addBodyPart(textPart);

        msg_body.addBodyPart(htmlPart);

        

        // Add the child container to the wrapper object.

        wrap.setContent(msg_body);

        

        // Create a multipart/mixed parent container.

        MimeMultipart msg = new MimeMultipart("mixed");

        

        // Add the parent container to the message.

        message.setContent(msg);

        

        // Add the multipart/alternative part to the message.

        msg.addBodyPart(wrap);

        

        // Define the attachment

        MimeBodyPart att = new MimeBodyPart();

        DataSource fds = new FileDataSource(ATTACHMENT);

        att.setDataHandler(new DataHandler(fds));

        att.setFileName(fds.getName());

        

        // Add the attachment to the message.

        msg.addBodyPart(att);


        // Try to send the email.

        try {

            System.out.println("Attempting to send an email through Amazon SES "

                              +"using the AWS SDK for Java...");


            // Instantiate an Amazon SES client, which will make the service 

            // call with the supplied AWS credentials.

            AmazonSimpleEmailService client = 

                    AmazonSimpleEmailServiceClientBuilder.standard()

                    // Replace US_WEST_2 with the AWS Region you're using for

                    // Amazon SES.

                    .withRegion(Regions.US_WEST_2).build();

            

            // Print the raw email content on the console

            PrintStream out = System.out;

            message.writeTo(out);


            // Send the email.

            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

            message.writeTo(outputStream);

            RawMessage rawMessage = 

            new RawMessage(ByteBuffer.wrap(outputStream.toByteArray()));


            SendRawEmailRequest rawEmailRequest = 

            new SendRawEmailRequest(rawMessage)

                .withConfigurationSetName(CONFIGURATION_SET);

            

            client.sendRawEmail(rawEmailRequest);

            System.out.println("Email sent!");

        // Display an error if something goes wrong.

        } catch (Exception ex) {

          System.out.println("Email Failed");

            System.err.println("Error message: " + ex.getMessage());

            ex.printStackTrace();

        }

    }

}

Thursday, 10 July 2025

Spring bean configuration with xml and java

If you want o use spring bean configuration with xml then you have to create bean.xml file


Monday, 30 June 2025

Revert a Specific File Committed that Pushed to Remote Git

You want to undo changes to just one file, even though the commit has already been pushed.

Option 1: Revert the file to the previous version and commit again (Safe & Recommended)

-----------------------------------------------------------------------

1. Revert the file to the version from the previous commit:

git checkout HEAD^ -- path/to/your/file

2. Stage the reverted file:

git add path/to/your/file

3. Commit the change:

git commit -m "Revert file to previous version"

4. Push to remote:

git push

Tip: You can use a specific commit hash instead of HEAD^

Option 2: Reset file to a specific older commit version (Safe if targeted)

------------------------------------------------------------

1. View commit history for the file:

git log path/to/file

2. Reset the file to that commit's version:

git checkout <commit-hash> -- path/to/file

3. Commit and push:

git add path/to/file

git commit -m "Revert file to specific commit version"

git pushOption 3: Revert the whole commit (only if the commit changed only this file)

-----------------------------------------------------------

git revert <commit-hash>

git push

Avoid:

------

Avoid using 'git reset --hard' and 'git push -f' on shared branches.

Always use a clean commit to revert individual file changes on shared remotes.

Friday, 30 May 2025

My sql do alter table on production -Percona's

 pt-online-schema-change \

  --alter "ADD INDEX idx_project_doc_filter (

    external_app_id,

    user_id,

    date_created DESC,

    design_name,

    subject_folder_id,

    listing_id,

    date_updated

  )" \

  --user=your_user \

  --password=your_pass \

  --host=your_host \

  --execute

Friday, 9 May 2025

spring swagger documentation

 https://springdoc.org/

<dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> <version>2.5.0</version> </dependency>