<?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/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4074627129522097342</id><updated>2025-04-19T16:45:01.250+05:30</updated><category term="java"/><category term="C#"/><category term="kotlin"/><category term="javascript"/><category term="kotlinlang.org"/><category term="kotinlang"/><category term="security"/><category term="jQuery"/><category term="spring boot"/><category term=".net"/><category term="database"/><category term="multi-tenancy"/><category term="multi-tenant"/><category term="SQL"/><category term="SaaS"/><category term="architecture"/><category term="iis"/><category term="react.js"/><category term="Microsoft"/><category term="github"/><category term="react"/><category term="spring"/><category term="JSON"/><category term="SQL Server"/><category term="apache"/><category term="blazor"/><category term="browser"/><category term="exception"/><category term="git"/><category term="maintainability"/><category term="map"/><category term="performance"/><category term="webassembly"/><category term="API"/><category term="C# samples"/><category term="DOM"/><category term="RuntimeException"/><category term="Serialization"/><category term="UncaughtExceptionHandler"/><category term="Windows Appfabric caching"/><category term="design"/><category term="dotnet core"/><category term="exceptionhandler"/><category term="filter"/><category term="linq"/><category term="mysql"/><category term="owin"/><category term="rest api"/><category term="sandbox"/><category term="setDefaultUncaughtExceptionHandler"/><category term="thread"/><category term="upgrade"/><category term=".net core"/><category term="Appfabric caching"/><category term="Cloud"/><category term="FxCop"/><category term="IIS Express"/><category term="IIS Express 8.0"/><category term="JS"/><category term="MVC"/><category term="MVC5"/><category term="NFR"/><category term="NFR&#39;s"/><category term="REST"/><category term="SupportNotificationExceptionHandler"/><category term="abstraction"/><category term="advice"/><category term="array destructuring"/><category term="asSequence"/><category term="asp.net mvc"/><category term="asp.net mvc2"/><category term="asp.net mvc5"/><category term="attack"/><category term="backup"/><category term="bytecode"/><category term="c sharp"/><category term="chrome"/><category term="collections"/><category term="component"/><category term="css"/><category term="data class"/><category term="data classes"/><category term="data migration"/><category term="debugging"/><category term="devops"/><category term="dotnet"/><category term="enum"/><category term="enumeration"/><category term="firefox"/><category term="git bash"/><category term="gitbash"/><category term="handle exceptions"/><category term="http2"/><category term="isolation"/><category term="jvm"/><category term="mysqldump"/><category term="mysqldump.exe"/><category term="owasp"/><category term="php"/><category term="restore database"/><category term="row level security"/><category term="sample code"/><category term="sequence"/><category term="singleton"/><category term="smart cast"/><category term="sql query"/><category term="ssl"/><category term="stackoverflow"/><category term="state"/><category term="tenancy"/><category term="tenant"/><category term="testing"/><category term="threads"/><category term="visual studio"/><category term="vulnerability"/><category term="ADFS"/><category term="AOT"/><category term="API documentation"/><category term="APIController"/><category term="ArrayIndexOutOfBoundsException"/><category term="BA"/><category term="C# code"/><category term="C# examples"/><category term="CAP"/><category term="CAP theorem"/><category term="Cloud Computing"/><category term="Consumer"/><category term="Context Consumer"/><category term="Context Provider"/><category term="CoreFTP"/><category term="DOM Rendering"/><category term="DTO"/><category term="Dot net"/><category term="Elon"/><category term="Elon Musk"/><category term="ExecutorService"/><category term="Executors"/><category term="GB"/><category term="IntelliJ"/><category term="JDK"/><category term="ListUtils"/><category term="PDF"/><category term="Provider"/><category term="RBAC"/><category term="RestController"/><category term="Runnable"/><category term="SAMEORIGIN"/><category term="SFTP"/><category term="SRS"/><category term="SharpSSH"/><category term="Software Development"/><category term="Software requirements"/><category term="TCP"/><category term="TLS"/><category term="TLS1.2"/><category term="TLS1.3"/><category term="Tamir.SharpSSH"/><category term="UDP"/><category term="Velocity Cache"/><category term="X-Frame-Options"/><category term="absolute expiration"/><category term="access denied"/><category term="after advice"/><category term="alias"/><category term="analysis"/><category term="anonymous"/><category term="anonymous objects"/><category term="aop"/><category term="apache tomcat"/><category term="app service"/><category term="applets"/><category term="application.properties"/><category term="array"/><category term="array of numbers as strings"/><category term="arrays"/><category term="asp.net mvc3"/><category term="aspect"/><category term="aspect oriented programming"/><category term="aspects"/><category term="associate"/><category term="associateBy"/><category term="associateWith"/><category term="async"/><category term="async await"/><category term="asynchronous"/><category term="authentication"/><category term="authentication gateway"/><category term="authorization"/><category term="auto update"/><category term="automation"/><category term="avro"/><category term="await"/><category term="aws"/><category term="aws policy"/><category term="azure"/><category term="backup table data as sql"/><category term="batch script"/><category term="before advice"/><category term="best practice"/><category term="binary"/><category term="blob"/><category term="block scope"/><category term="business analyst"/><category term="c++"/><category term="cache"/><category term="cache expiration"/><category term="cart"/><category term="cast operators"/><category term="cer"/><category term="choice of right feature"/><category term="chrome test"/><category term="chromedriver"/><category term="chunks"/><category term="ci-cd"/><category term="class"/><category term="client"/><category term="client-side execution"/><category term="clone table data"/><category term="clone table schema"/><category term="code duplication"/><category term="code readability"/><category term="collection destructuring"/><category term="collection intersection"/><category term="collections4"/><category term="collectionutils"/><category term="command line"/><category term="commands"/><category term="companion"/><category term="companion object"/><category term="comparable"/><category term="compareTo"/><category term="comparison"/><category term="compiler"/><category term="concise"/><category term="concurrency"/><category term="const"/><category term="constructor"/><category term="constructors"/><category term="context"/><category term="context api"/><category term="contextapi"/><category term="controller advice"/><category term="copy"/><category term="count"/><category term="cross cutting concerns"/><category term="cryptography"/><category term="csv"/><category term="custom exceptions"/><category term="custom response from fixed class"/><category term="custom roles"/><category term="custom serialization"/><category term="custom type name on import"/><category term="data"/><category term="data encoding"/><category term="data format"/><category term="data model"/><category term="data validation"/><category term="database migration"/><category term="datatables"/><category term="date range"/><category term="dates"/><category term="debouncing"/><category term="delete jenkins job"/><category term="delete job"/><category term="demo"/><category term="deployment"/><category term="deployments"/><category term="deserialization"/><category term="developer"/><category term="developer productivity"/><category term="digital certificates"/><category term="distributed database"/><category term="documentation"/><category term="download"/><category term="dsaravanan"/><category term="dynamic object creation"/><category term="dynamic objects"/><category term="ef"/><category term="efcore"/><category term="encoding"/><category term="entity"/><category term="entity framework core"/><category term="entity policies"/><category term="enum class"/><category term="etl"/><category term="events"/><category term="exception constructors"/><category term="exceptions"/><category term="expressions"/><category term="extension"/><category term="extension functions"/><category term="extensions"/><category term="extract value"/><category term="extractor"/><category term="facebook"/><category term="factory"/><category term="factory design pattern"/><category term="factory methods"/><category term="factory pattern"/><category term="fault tolerance"/><category term="fetch"/><category term="fetch api"/><category term="fiddles"/><category term="filtered data in backup"/><category term="filtering"/><category term="final advice"/><category term="finally advice"/><category term="find"/><category term="flatMap"/><category term="framework"/><category term="function scope"/><category term="gateway"/><category term="general"/><category term="generics"/><category term="genius"/><category term="git bash alias"/><category term="git config"/><category term="git global config"/><category term="git user config"/><category term="global.asax"/><category term="gnupg"/><category term="google chrome"/><category term="gpg"/><category term="gpg-agent reload"/><category term="gpg-connect-agent"/><category term="groovy"/><category term="groupby"/><category term="handle logic"/><category term="hashicorp"/><category term="hashicorp vault"/><category term="headers"/><category term="hide property from serialization"/><category term="hierarchy"/><category term="hosted application"/><category term="html"/><category term="http"/><category term="http/2"/><category term="http/3"/><category term="http1.1"/><category term="http3"/><category term="iTextSharp"/><category term="iframe"/><category term="iframes"/><category term="import"/><category term="important points in php"/><category term="india"/><category term="inline"/><category term="inlining"/><category term="interfaces"/><category term="interoperable"/><category term="intersect"/><category term="intersection"/><category term="introduction"/><category term="it"/><category term="iteration"/><category term="jenkins"/><category term="jenkins delete project"/><category term="jenkins job"/><category term="jenkins jobs"/><category term="jetbrains"/><category term="jit"/><category term="jit compilation"/><category term="jobs"/><category term="jsbin"/><category term="json array"/><category term="json path"/><category term="json property"/><category term="jsonview"/><category term="jsonviews"/><category term="katana"/><category term="key-value"/><category term="keys"/><category term="keystrokes"/><category term="large files"/><category term="lazy"/><category term="learning php"/><category term="let"/><category term="lifecycle"/><category term="lifecycle events"/><category term="linq to sql"/><category term="list diff"/><category term="list intersection"/><category term="litespeed"/><category term="logic"/><category term="manipulation"/><category term="map destructuring"/><category term="maxByOrNull"/><category term="mb"/><category term="memory"/><category term="memory sharing"/><category term="methods"/><category term="microservices"/><category term="middleware"/><category term="mitigation"/><category term="motivation"/><category term="mvc2 to mvc3"/><category term="ncu"/><category term="ncu --upgrade"/><category term="network"/><category term="network analyzer"/><category term="new blog"/><category term="newtonsoft"/><category term="newtonsoft.json"/><category term="next"/><category term="next.js"/><category term="nosql"/><category term="npm"/><category term="npm install"/><category term="oauth"/><category term="object creation"/><category term="object destructuring"/><category term="openapi"/><category term="opensource tools"/><category term="operator overloading"/><category term="package.json"/><category term="pages"/><category term="pages in next.js"/><category term="parameter"/><category term="params"/><category term="parse string as integers"/><category term="parseInt"/><category term="parser"/><category term="partition"/><category term="passwords"/><category term="paste"/><category term="payload"/><category term="pdb"/><category term="pdb files"/><category term="performance testing"/><category term="pfx"/><category term="php key terms"/><category term="pointcut"/><category term="pointcuts"/><category term="policy"/><category term="policy enforcement"/><category term="policy manager"/><category term="policy store"/><category term="policy validation"/><category term="portals"/><category term="postman"/><category term="private constructor"/><category term="productivity"/><category term="property"/><category term="props"/><category term="provisioning"/><category term="publish"/><category term="python"/><category term="questionnaire"/><category term="questions"/><category term="quic"/><category term="range"/><category term="range check"/><category term="react 18"/><category term="react context api"/><category term="reduce redundancy"/><category term="reducer"/><category term="reified"/><category term="reified T"/><category term="reify"/><category term="release"/><category term="rename imports"/><category term="rendering"/><category term="replication"/><category term="request"/><category term="requirements"/><category term="response headers"/><category term="restart"/><category term="restore database using sql script"/><category term="return values"/><category term="returning advice"/><category term="riak"/><category term="riak database"/><category term="rls"/><category term="robot"/><category term="robot framework"/><category term="role permissions"/><category term="role privileges"/><category term="role tenants"/><category term="roles"/><category term="roles based access control"/><category term="rpa"/><category term="rust"/><category term="s.dorai"/><category term="s3"/><category term="s3 policy"/><category term="saravanan"/><category term="savings"/><category term="scability"/><category term="scalability"/><category term="schema change and migration"/><category term="scope"/><category term="script"/><category term="secrets"/><category term="secure"/><category term="secure access"/><category term="secure sandbox"/><category term="server"/><category term="sharding"/><category term="shortcuts"/><category term="signature"/><category term="siliding expiration"/><category term="singletons"/><category term="snippet"/><category term="sortedByDescending"/><category term="sorting"/><category term="spacex"/><category term="specifications"/><category term="spinner"/><category term="split"/><category term="spring cloud config server"/><category term="springfox"/><category term="sql injection"/><category term="sql script"/><category term="stackoverflow.com"/><category term="starlink"/><category term="startTransition"/><category term="state management"/><category term="static contents"/><category term="strategies"/><category term="stream"/><category term="streams"/><category term="string"/><category term="string comparison"/><category term="string formatting for enum"/><category term="strings"/><category term="subset of entity properties"/><category term="subtract"/><category term="swagger"/><category term="swagger-ui"/><category term="switch"/><category term="switch case"/><category term="symbolsource"/><category term="tax"/><category term="tenant roles"/><category term="tenant to role mapping"/><category term="terminal"/><category term="terminal operation"/><category term="terminal operator"/><category term="terse code"/><category term="tesla"/><category term="theming"/><category term="threat"/><category term="throwing advice"/><category term="time management"/><category term="time saving"/><category term="tips and tricks"/><category term="toSet"/><category term="tomcat"/><category term="tools"/><category term="tostring"/><category term="transition"/><category term="type casting"/><category term="type erasure"/><category term="update"/><category term="upgrade from mvc2 to mvc3"/><category term="uplifting state"/><category term="useContext"/><category term="useReducer"/><category term="useState"/><category term="useTransition"/><category term="useful commands"/><category term="user authentication"/><category term="user defined exception"/><category term="user security"/><category term="users"/><category term="validation"/><category term="var"/><category term="varargs"/><category term="variable arguments"/><category term="variables"/><category term="vault"/><category term="verification"/><category term="verififed commit"/><category term="version"/><category term="visual studio 2013"/><category term="wasm"/><category term="web"/><category term="web apps"/><category term="web security"/><category term="web.config"/><category term="webapi"/><category term="webdriver"/><category term="webservice"/><category term="welcome"/><category term="when"/><category term="windows"/><category term="windows server"/><category term="wireshark"/><title type='text'>Software And Architecture</title><subtitle type='html'>I have 11+ years of experience in Software development. I am proud  to be in the top 5 Multi-Tenancy answerers @ Stackoverflow. &#xa;I have worked with C#, Java, MySQL, SQL Server, Multi-tenancy, AWS, Azure, Terraforms, Java with Spring boot and Python, groovy, bat scripts</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>132</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-409392392681282968</id><published>2023-08-29T21:09:00.009+05:30</published><updated>2025-04-19T15:56:03.729+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="blazor"/><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="events"/><category scheme="http://www.blogger.com/atom/ns#" term="lifecycle"/><category scheme="http://www.blogger.com/atom/ns#" term="lifecycle events"/><title type='text'>Blazor component lifecycle events</title><content type='html'>&lt;title&gt;Lifecycle of Blazor Components&lt;/title&gt;
&lt;h1&gt;Blazor Component Lifecycle Events&lt;/h1&gt;
&lt;meta name=&quot;description&quot; content=&quot;Learn about Blazor lifecycle methods, including OnInitializedAsync and OnAfterRenderAsync, to optimize your Blazor applications.&quot;&gt;&lt;/meta&gt;
&lt;p&gt;Blazor components have a lifecycle that defines the various stages a component goes through from its creation to its disposal. Understanding the component lifecycle is crucial for managing state, optimizing performance, and responding to events. Here&amp;#39;s an overview of the Blazor component lifecycle events along with sample code to illustrate each stage:&lt;/p&gt;
&lt;h2&gt;Understanding OnInitialized, OnInitializedAsync&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Initialization&lt;/strong&gt;: This is the initial stage where the component&amp;#39;s parameters and dependencies are set. It happens before rendering.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;lang-csharp&quot;&gt;@code {
    [Parameter] &lt;span class=&quot;hljs-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;string&lt;/span&gt; Message { &lt;span class=&quot;hljs-keyword&quot;&gt;get&lt;/span&gt;; &lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt;; }

    &lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;OnInitialized&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;&lt;/span&gt;)
    &lt;/span&gt;{
        &lt;span class=&quot;hljs-comment&quot;&gt;// Initialization logic&lt;/span&gt;
    }
}

&amp;lt;h3&amp;gt;@Message&amp;lt;/h3&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Initialize a database connection&lt;/li&gt;
&lt;li&gt;Load data from a server&lt;/li&gt;
&lt;li&gt;Set up bindings&lt;/li&gt;
&lt;li&gt;Create timers or other asynchronous tasks&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Parameter Set&lt;/strong&gt;: This stage occurs when component parameters are set. It can be useful for reacting to changes in parameters.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;lang-csharp&quot;&gt;@code {
    [Parameter] &lt;span class=&quot;hljs-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;string&lt;/span&gt; Message { &lt;span class=&quot;hljs-keyword&quot;&gt;get&lt;/span&gt;; &lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt;; }

    &lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;OnParametersSet&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;&lt;/span&gt;)
    &lt;/span&gt;{
        &lt;span class=&quot;hljs-comment&quot;&gt;// Parameter set logic&lt;/span&gt;
    }
}

&amp;lt;h3&amp;gt;@Message&amp;lt;/h3&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Update the component&amp;#39;s title&lt;/li&gt;
&lt;li&gt;Update the data it is displaying&lt;/li&gt;
&lt;li&gt;Change its behavior based on the new parameters&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Render&lt;/strong&gt;: This is where the component&amp;#39;s rendering logic occurs. It happens after parameters are set.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;lang-csharp&quot;&gt;@code {
    [Parameter] &lt;span class=&quot;hljs-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;string&lt;/span&gt; Message { &lt;span class=&quot;hljs-keyword&quot;&gt;get&lt;/span&gt;; &lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt;; }

    &lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;BuildRenderTree&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;RenderTreeBuilder builder&lt;/span&gt;)
    &lt;/span&gt;{
        &lt;span class=&quot;hljs-comment&quot;&gt;// Render logic&lt;/span&gt;
    }
}

&amp;lt;h3&amp;gt;@Message&amp;lt;/h3&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;OnAfterRender/OnAfterRenderAsync&lt;/strong&gt;: These events occur after the component has been rendered and added to the UI. They are useful for interacting with the rendered DOM elements.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;lang-csharp&quot;&gt;@code {
    [Parameter]&lt;span class=&quot;hljs-keyword&quot;&gt; public&lt;/span&gt; string Message { get; set; }

   &lt;span class=&quot;hljs-keyword&quot;&gt; protected&lt;/span&gt; override void OnAfterRender(bool firstRender)
    {
       &lt;span class=&quot;hljs-built_in&quot;&gt; if &lt;/span&gt;(firstRender)
        {
            // Logic to&lt;span class=&quot;hljs-built_in&quot;&gt; execute &lt;/span&gt;after first render
        }
    }
}

&amp;lt;h3&amp;gt;@Message&amp;lt;/h3&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Update the component&amp;#39;s state in response to user input&lt;/li&gt;
&lt;li&gt;Make asynchronous calls&lt;/li&gt;
&lt;li&gt;Handle errors&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Update&lt;/strong&gt;: This stage happens when the component needs to update due to changes in parameters or state.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;lang-csharp&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;@code&lt;/span&gt; {
    &lt;span class=&quot;hljs-keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;int&lt;/span&gt; count = &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;;

    &lt;span class=&quot;hljs-keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;void&lt;/span&gt; IncrementCount()
    {
        count++;
    }

    &lt;span class=&quot;hljs-keyword&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;hljs-built_in&quot;&gt;bool&lt;/span&gt; ShouldRender()
    {
        &lt;span class=&quot;hljs-comment&quot;&gt;// Custom logic to determine whether to render&lt;/span&gt;
        &lt;span class=&quot;hljs-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;true&lt;/span&gt;;
    }
}

&amp;lt;button &lt;span class=&quot;hljs-keyword&quot;&gt;@onclick&lt;/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;IncrementCount&quot;&lt;/span&gt;&amp;gt;Increment&amp;lt;/button&amp;gt;
&amp;lt;p&amp;gt;Count: &lt;span class=&quot;hljs-keyword&quot;&gt;@count&lt;/span&gt;&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Dispose&lt;/strong&gt;: This is the final stage when the component is removed from the UI. It&amp;#39;s useful for cleaning up resources.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;lang-csharp&quot;&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@implements&lt;/span&gt; IDisposable

&lt;span class=&quot;hljs-variable&quot;&gt;@code&lt;/span&gt; {
    &lt;span class=&quot;hljs-comment&quot;&gt;// Component logic&lt;/span&gt;

    &lt;span class=&quot;hljs-selector-tag&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hljs-selector-tag&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;hljs-selector-tag&quot;&gt;Dispose&lt;/span&gt;()
    {
        &lt;span class=&quot;hljs-comment&quot;&gt;// Cleanup logic&lt;/span&gt;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Blazor lifecycle methods, such as OnInitializedAsync, are crucial for managing state and optimizing performance in Blazor applications.&lt;/p&gt;
&lt;p&gt;Remember that Blazor also has asynchronous versions of some lifecycle events, such as &lt;code&gt;OnInitializedAsync&lt;/code&gt;, &lt;code&gt;OnParametersSetAsync&lt;/code&gt;, and &lt;code&gt;OnAfterRenderAsync&lt;/code&gt;. These can be used when you need to perform asynchronous operations during those stages.&lt;/p&gt;
&lt;p&gt;It&amp;#39;s important to note that you might not always need to use all of these lifecycle events for every component. Choose the ones that fit your needs and make your code efficient and maintainable.&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/409392392681282968/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/blazor-component-lifecycle-events.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/409392392681282968'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/409392392681282968'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/blazor-component-lifecycle-events.html' title='Blazor component lifecycle events'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-2755959133081087875</id><published>2023-08-28T19:17:00.000+05:30</published><updated>2023-08-28T19:17:32.135+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="async"/><category scheme="http://www.blogger.com/atom/ns#" term="async await"/><category scheme="http://www.blogger.com/atom/ns#" term="asynchronous"/><category scheme="http://www.blogger.com/atom/ns#" term="await"/><category scheme="http://www.blogger.com/atom/ns#" term="blazor"/><title type='text'>Async implementation in Blazor</title><content type='html'>&lt;h2&gt;&lt;strong&gt;Step-by-Step Guide to Achieving Async Flows in Blazor:&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;1. Understanding Asynchronous Programming:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Before delving into Blazor-specific async flows, it&amp;#39;s crucial to understand asynchronous programming concepts like &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;await&lt;/code&gt;. Asynchronous operations help improve the responsiveness of your UI by not blocking the main thread.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. Blazor Component Lifecycle:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Blazor components have their lifecycle methods. The &lt;code&gt;OnInitializedAsync&lt;/code&gt;, &lt;code&gt;OnParametersSetAsync&lt;/code&gt;, and &lt;code&gt;OnAfterRenderAsync&lt;/code&gt; methods allow you to implement asynchronous operations during various stages of a component&amp;#39;s lifecycle.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. Asynchronous API Calls:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Performing asynchronous API calls is a common scenario in web applications. You can use &lt;code&gt;HttpClient&lt;/code&gt; to make HTTP requests asynchronously. For example, fetching data from a remote server:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;lang-csharp&quot;&gt;@page &lt;span class=&quot;hljs-string&quot;&gt;&quot;/fetchdata&quot;&lt;/span&gt;

@inject HttpClient Http

@&lt;span class=&quot;hljs-keyword&quot;&gt;if&lt;/span&gt; (forecasts == &lt;span class=&quot;hljs-literal&quot;&gt;null&lt;/span&gt;)
{
    &amp;lt;p&amp;gt;&lt;span class=&quot;xml&quot;&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;em&lt;/span&gt;&amp;gt;&lt;/span&gt;Loading...&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;em&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;xml&quot;&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;p&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
}
&lt;span class=&quot;hljs-keyword&quot;&gt;else&lt;/span&gt;
{
    &amp;lt;table&amp;gt;
        &lt;span class=&quot;xml&quot;&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&amp;lt;!-- Display data here --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;table&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
}

@code {
    private WeatherForecast[] forecasts;

    protected override &lt;span class=&quot;hljs-keyword&quot;&gt;async&lt;/span&gt; Task OnInitializedAsync()
    {
        forecasts = &lt;span class=&quot;hljs-keyword&quot;&gt;await&lt;/span&gt; Http.GetFromJsonAsync&amp;lt;WeatherForecast[]&amp;gt;(&lt;span class=&quot;hljs-string&quot;&gt;&quot;sample-data/weather.json&quot;&lt;/span&gt;);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;4. Using &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;await&lt;/code&gt; in Event Handlers:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You can use &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;await&lt;/code&gt; within event handlers, allowing you to perform asynchronous tasks in response to user actions.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;lang-csharp&quot;&gt;&amp;lt;button &lt;span class=&quot;hljs-meta&quot;&gt;@onclick&lt;/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;FetchData&quot;&lt;/span&gt;&amp;gt;Fetch Data&amp;lt;/button&amp;gt;

&amp;lt;p&amp;gt;&lt;span class=&quot;hljs-meta&quot;&gt;@data&lt;/span&gt;&amp;lt;/p&amp;gt;

&lt;span class=&quot;hljs-meta&quot;&gt;@code&lt;/span&gt; {
    &lt;span class=&quot;hljs-keyword&quot;&gt;private&lt;/span&gt; string &lt;span class=&quot;hljs-keyword&quot;&gt;data&lt;/span&gt;;

    &lt;span class=&quot;hljs-keyword&quot;&gt;private&lt;/span&gt; async Task FetchData()
    {
        &lt;span class=&quot;hljs-keyword&quot;&gt;data&lt;/span&gt; = &lt;span class=&quot;hljs-string&quot;&gt;&quot;Fetching...&quot;&lt;/span&gt;;
        &lt;span class=&quot;hljs-comment&quot;&gt;// Simulate async work&lt;/span&gt;
        await Task.Delay(&lt;span class=&quot;hljs-number&quot;&gt;1000&lt;/span&gt;);
        &lt;span class=&quot;hljs-keyword&quot;&gt;data&lt;/span&gt; = &lt;span class=&quot;hljs-string&quot;&gt;&quot;Data fetched!&quot;&lt;/span&gt;;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;5. Handling Multiple Asynchronous Operations:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In some cases, you might need to await multiple asynchronous operations and proceed when all are completed. You can use &lt;code&gt;Task.WhenAll&lt;/code&gt; for this purpose.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;lang-csharp&quot;&gt;&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;async&lt;/span&gt; Task &lt;span class=&quot;hljs-title&quot;&gt;HandleMultipleAsyncOperations&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;&lt;/span&gt;)
&lt;/span&gt;{
    &lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;/span&gt; task1 = SomeAsyncMethod1();
    &lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;/span&gt; task2 = SomeAsyncMethod2();

    &lt;span class=&quot;hljs-keyword&quot;&gt;await&lt;/span&gt; Task.WhenAll(task1, task2);

    &lt;span class=&quot;hljs-comment&quot;&gt;// Both tasks completed&lt;/span&gt;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;6. Error Handling:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When dealing with asynchronous operations, you need to handle exceptions properly. Use &lt;code&gt;try-catch&lt;/code&gt; blocks to catch and handle exceptions that might occur during asynchronous tasks.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;lang-csharp&quot;&gt;&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;async&lt;/span&gt; Task &lt;span class=&quot;hljs-title&quot;&gt;FetchData&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;&lt;/span&gt;)
&lt;/span&gt;{
    &lt;span class=&quot;hljs-keyword&quot;&gt;try&lt;/span&gt;
    {
        &lt;span class=&quot;hljs-comment&quot;&gt;// Async operation that might throw an exception&lt;/span&gt;
        data = &lt;span class=&quot;hljs-keyword&quot;&gt;await&lt;/span&gt; FetchDataFromServer();
    }
    &lt;span class=&quot;hljs-keyword&quot;&gt;catch&lt;/span&gt; (Exception ex)
    {
        &lt;span class=&quot;hljs-comment&quot;&gt;// Handle the exception&lt;/span&gt;
        data = &lt;span class=&quot;hljs-string&quot;&gt;&quot;Error fetching data: &quot;&lt;/span&gt; + ex.Message;
    }
}
&lt;/code&gt;&lt;/pre&gt;

</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/2755959133081087875/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/async-implementation-in-blazor.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/2755959133081087875'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/2755959133081087875'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/async-implementation-in-blazor.html' title='Async implementation in Blazor'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-2042903578266408070</id><published>2023-08-27T16:12:00.003+05:30</published><updated>2023-08-28T18:52:54.656+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="AOT"/><category scheme="http://www.blogger.com/atom/ns#" term="binary"/><category scheme="http://www.blogger.com/atom/ns#" term="bytecode"/><category scheme="http://www.blogger.com/atom/ns#" term="compiler"/><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="jit"/><category scheme="http://www.blogger.com/atom/ns#" term="jit compilation"/><category scheme="http://www.blogger.com/atom/ns#" term="memory"/><category scheme="http://www.blogger.com/atom/ns#" term="memory sharing"/><category scheme="http://www.blogger.com/atom/ns#" term="parser"/><category scheme="http://www.blogger.com/atom/ns#" term="wasm"/><category scheme="http://www.blogger.com/atom/ns#" term="webassembly"/><title type='text'>Architecture of WebAssembly</title><content type='html'>&lt;h1 id=&quot;webassembly-architecture-and-browser-integration&quot;&gt;WebAssembly Architecture and Browser Integration&lt;/h1&gt;
&lt;p&gt;WebAssembly (Wasm) is a revolutionary technology that enables efficient execution of code in web browsers at near-native speeds. Its architecture involves a combination of components within the browser that work together to compile, load, and execute WebAssembly modules. In this detailed article, we will delve into the architecture of WebAssembly and explore how it integrates with browser components to enable seamless execution of Wasm modules.&lt;/p&gt;
&lt;h2 id=&quot;webassembly-architecture-overview&quot;&gt;WebAssembly Architecture Overview&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Source Code&lt;/strong&gt;: Developers write code in high-level programming languages like C, C++, Rust, or even languages like Python through transpilers. This code is then compiled to WebAssembly binary format (&lt;code&gt;.wasm&lt;/code&gt; files).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;WebAssembly Binary Format&lt;/strong&gt;: The WebAssembly binary format is a low-level, compact bytecode representation of the source code. It is designed for efficient and secure execution in web browsers. This binary format is portable and can be delivered over the internet.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Browser Components&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Parser&lt;/strong&gt;: When a Wasm module is fetched, the browser&amp;#39;s parser interprets the binary data and converts it into an Abstract Syntax Tree (AST). This AST represents the structure and semantics of the WebAssembly code.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Validator&lt;/strong&gt;: The validator checks the validity and safety of the Wasm module. It ensures that the module adheres to the WebAssembly specification, preventing malicious or erroneous code from running.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Compiler&lt;/strong&gt;: Once validated, the compiler translates the WebAssembly code into machine code that is suitable for the target architecture. This machine code is optimized for efficient execution.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Memory Management&lt;/strong&gt;: WebAssembly operates in a linear memory model. Browsers allocate a memory buffer for the module to use. The module interacts with this memory using load and store instructions.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Execution Engine&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;JIT Compilation&lt;/strong&gt;: Just-In-Time (JIT) compilation involves compiling the WebAssembly module into native machine code at runtime, just before execution. This compiled code is then executed by the browser&amp;#39;s JavaScript engine.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ahead-of-Time Compilation (AOT)&lt;/strong&gt;: Some browsers offer the option to perform Ahead-of-Time compilation, where the Wasm module is compiled to native machine code ahead of time, reducing the runtime overhead.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Integration with JavaScript&lt;/strong&gt;: WebAssembly can interact with JavaScript code through a mechanism called the WebAssembly JavaScript API. This API allows JavaScript and WebAssembly to call each other&amp;#39;s functions, share data, and collaborate seamlessly.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;browser-components-for-running-webassembly&quot;&gt;Browser Components for Running WebAssembly&lt;/h2&gt;
&lt;h3 id=&quot;parser-and-validator-&quot;&gt;Parser and Validator:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;The browser&amp;#39;s parser reads the fetched WebAssembly binary and converts it into an AST.&lt;/li&gt;
&lt;li&gt;The validator checks the module&amp;#39;s structure, types, and control flow, ensuring it adheres to the WebAssembly specification.&lt;/li&gt;
&lt;li&gt;Invalid or malicious code is rejected during validation to maintain security.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;compiler-&quot;&gt;Compiler:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;The compiler translates the validated WebAssembly code into machine code.&lt;/li&gt;
&lt;li&gt;Browsers may use various compilation strategies, including JIT compilation or AOT compilation, to optimize execution speed.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;memory-management-&quot;&gt;Memory Management:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;WebAssembly operates with a linear memory model, which is a contiguous block of memory accessible by the module.&lt;/li&gt;
&lt;li&gt;The browser allocates memory for the WebAssembly module, and the module interacts with this memory using load and store instructions.&lt;/li&gt;
&lt;li&gt;Typed arrays in JavaScript can be used to share data between JavaScript and WebAssembly.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;execution-engine-&quot;&gt;Execution Engine:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;The JIT compiler translates the WebAssembly module into native machine code, optimizing it for the target architecture.&lt;/li&gt;
&lt;li&gt;The JIT-compiled code is executed by the browser&amp;#39;s JavaScript engine, which manages memory, execution flow, and interactions with other browser components.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;webassembly-javascript-api-&quot;&gt;WebAssembly JavaScript API:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;The WebAssembly JavaScript API allows JavaScript and WebAssembly code to communicate and collaborate.&lt;/li&gt;
&lt;li&gt;JavaScript can call WebAssembly functions and vice versa, enabling seamless integration between the two.&lt;/li&gt;
&lt;li&gt;This API also facilitates data sharing, allowing efficient exchange of data between JavaScript and WebAssembly.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;WebAssembly&amp;#39;s architecture involves a sequence of steps, from source code to execution, that work together to enable efficient and secure execution of code within web browsers. Browser components such as parsers, validators, compilers, memory managers, execution engines, and the WebAssembly JavaScript API collaborate to ensure that WebAssembly modules are safely and optimally executed. This integration of technologies empowers developers to build high-performance web applications that leverage the strengths of WebAssembly. As the technology continues to evolve, WebAssembly&amp;#39;s impact on web development is expected to be significant and far-reaching.&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/2042903578266408070/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/architecture-of-webassembly.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/2042903578266408070'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/2042903578266408070'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/architecture-of-webassembly.html' title='Architecture of WebAssembly'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-644781396664692327</id><published>2023-08-27T16:07:00.002+05:30</published><updated>2023-08-28T18:52:59.910+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="applets"/><category scheme="http://www.blogger.com/atom/ns#" term="architecture"/><category scheme="http://www.blogger.com/atom/ns#" term="bytecode"/><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="comparison"/><category scheme="http://www.blogger.com/atom/ns#" term="dotnet"/><category scheme="http://www.blogger.com/atom/ns#" term="dotnet core"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="jvm"/><category scheme="http://www.blogger.com/atom/ns#" term="performance"/><category scheme="http://www.blogger.com/atom/ns#" term="sandbox"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><category scheme="http://www.blogger.com/atom/ns#" term="webassembly"/><title type='text'>WebAssembly vs Java Applets</title><content type='html'>&lt;h1 id=&quot;a-detailed-comparison-webassembly-vs-java-applets&quot;&gt;A Detailed Comparison: WebAssembly vs. Java Applets&lt;/h1&gt;
&lt;p&gt;WebAssembly and Java Applets are technologies aimed at enhancing web applications by enabling execution of code directly in the browser. However, they have significant differences in terms of architecture, performance, security, and modern web development practices. Let&amp;#39;s compare these two technologies in-depth, along with scenarios and code samples.&lt;/p&gt;
&lt;h2 id=&quot;webassembly&quot;&gt;WebAssembly&lt;/h2&gt;
&lt;h3 id=&quot;architecture-&quot;&gt;Architecture:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;WebAssembly is a binary instruction format that allows high-level languages to be compiled into a low-level bytecode that can run efficiently in browsers.&lt;/li&gt;
&lt;li&gt;It provides a secure sandboxed environment where code can execute without direct access to browser internals.&lt;/li&gt;
&lt;li&gt;WebAssembly modules can be integrated into web applications, enabling performance-critical components to run faster than JavaScript.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;performance-&quot;&gt;Performance:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;WebAssembly code can achieve near-native performance, making it suitable for applications requiring complex computations or real-time interactions.&lt;/li&gt;
&lt;li&gt;Execution is highly optimized due to its low-level nature and efficient bytecode representation.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;security-&quot;&gt;Security:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;WebAssembly&amp;#39;s sandboxed execution environment enhances security by isolating code from the host environment.&lt;/li&gt;
&lt;li&gt;It limits direct access to the DOM and browser APIs, reducing the attack surface for potential vulnerabilities.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;modern-web-development-&quot;&gt;Modern Web Development:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;WebAssembly aligns well with modern web development practices, where applications are often built using diverse technologies and languages.&lt;/li&gt;
&lt;li&gt;Developers can use languages like C++, Rust, and C# and compile them to WebAssembly, offering a broader range of language choices.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;sample-code-&quot;&gt;Sample Code:&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;lang-c&quot;&gt;&lt;span class=&quot;hljs-comment&quot;&gt;// WebAssembly C code example&lt;/span&gt;
&lt;span class=&quot;hljs-meta&quot;&gt;#&lt;span class=&quot;hljs-meta-keyword&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;hljs-meta-string&quot;&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;/span&gt;

&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;hljs-params&quot;&gt;()&lt;/span&gt; &lt;/span&gt;{
    &lt;span class=&quot;hljs-built_in&quot;&gt;printf&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Hello, WebAssembly!\n&quot;&lt;/span&gt;);
    &lt;span class=&quot;hljs-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;java-applets&quot;&gt;Java Applets&lt;/h2&gt;
&lt;h3 id=&quot;architecture-&quot;&gt;Architecture:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Java Applets are small Java programs that run inside a browser using a Java Virtual Machine (JVM).&lt;/li&gt;
&lt;li&gt;They were historically used for adding interactive elements to web pages, such as animations and mini-games.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;performance-&quot;&gt;Performance:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Java Applets can suffer from performance issues due to the overhead of running a Java Virtual Machine within the browser.&lt;/li&gt;
&lt;li&gt;JVM startup and memory consumption could be relatively high, impacting the user experience.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;security-&quot;&gt;Security:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Java Applets faced security challenges, leading to vulnerabilities. They could access system resources and pose security risks.&lt;/li&gt;
&lt;li&gt;Modern browsers have largely deprecated support for Java Applets due to security concerns.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;modern-web-development-&quot;&gt;Modern Web Development:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Java Applets are not aligned with modern web development practices, as they require using Java, which is less common for web application development.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;sample-code-&quot;&gt;Sample Code:&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;lang-java&quot;&gt;&lt;span class=&quot;hljs-comment&quot;&gt;// Java Applet example (deprecated)&lt;/span&gt;
&lt;span class=&quot;hljs-keyword&quot;&gt;import&lt;/span&gt; java.applet.&lt;span class=&quot;hljs-type&quot;&gt;Applet&lt;/span&gt;;
&lt;span class=&quot;hljs-keyword&quot;&gt;import&lt;/span&gt; java.awt.&lt;span class=&quot;hljs-type&quot;&gt;Graphics&lt;/span&gt;;

public &lt;span class=&quot;hljs-class&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;HelloWorldApplet&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;Applet&lt;/span&gt; &lt;/span&gt;{
    public void paint(&lt;span class=&quot;hljs-type&quot;&gt;Graphics&lt;/span&gt; g) {
        g.drawString(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Hello, Java Applet!&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot;&gt;50&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot;&gt;25&lt;/span&gt;);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;scenarios-and-comparison-&quot;&gt;Scenarios and Comparison:&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Performance-Critical Tasks&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;WebAssembly is better suited for performance-critical tasks due to its low-level compilation and near-native execution speed.&lt;/li&gt;
&lt;li&gt;Java Applets could suffer from overhead due to the JVM and might not provide the same level of performance as WebAssembly.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security and Compatibility&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;WebAssembly&amp;#39;s sandboxed environment enhances security by isolating code execution.&lt;/li&gt;
&lt;li&gt;Java Applets historically faced security issues, and modern browsers have largely deprecated support for them due to these concerns.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Language and Ecosystem&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;WebAssembly allows developers to use various programming languages and leverage existing ecosystems, making it more versatile.&lt;/li&gt;
&lt;li&gt;Java Applets are limited to Java, which might not align well with the diverse set of languages used in modern web development.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Integration with Modern Web Standards&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;WebAssembly aligns with modern web development practices, as it integrates well with HTML, CSS, and JavaScript.&lt;/li&gt;
&lt;li&gt;Java Applets do not integrate as seamlessly with these modern standards.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;User Experience&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;WebAssembly can provide a smoother user experience with its potential for better performance.&lt;/li&gt;
&lt;li&gt;Java Applets could lead to slower page loads and less responsiveness due to JVM startup time.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;In summary, while both WebAssembly and Java Applets aim to enhance web applications with executable code in the browser, WebAssembly has emerged as a more viable option due to its performance, security improvements, and alignment with modern web development practices. Java Applets, on the other hand, have largely fallen out of favor due to security concerns and their limitations in the modern web landscape.&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/644781396664692327/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/webassembly-vs-java-applets.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/644781396664692327'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/644781396664692327'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/webassembly-vs-java-applets.html' title='WebAssembly vs Java Applets'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-2775401860308709937</id><published>2023-08-27T16:02:00.006+05:30</published><updated>2023-08-27T16:02:54.586+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="blazor"/><category scheme="http://www.blogger.com/atom/ns#" term="browser"/><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="client-side execution"/><category scheme="http://www.blogger.com/atom/ns#" term="dotnet core"/><category scheme="http://www.blogger.com/atom/ns#" term="rust"/><category scheme="http://www.blogger.com/atom/ns#" term="sandbox"/><category scheme="http://www.blogger.com/atom/ns#" term="web apps"/><category scheme="http://www.blogger.com/atom/ns#" term="webassembly"/><title type='text'>Overview of WebAssembly</title><content type='html'>&lt;h1 id=&quot;webassembly-revolutionizing-web-application-development&quot;&gt;WebAssembly: Revolutionizing Web Application Development&lt;/h1&gt;
&lt;p&gt;WebAssembly (Wasm) is a groundbreaking technology that enables developers to run high-performance code in web browsers at near-native speeds. It has the potential to significantly change the way web applications are built, offering new levels of performance, security, and cross-platform compatibility. In this article, we&amp;#39;ll explore what WebAssembly is, how it affects web app development, and provide a detailed example of building an e-commerce application using C# and .NET Core.&lt;/p&gt;
&lt;h2 id=&quot;what-is-webassembly-&quot;&gt;What is WebAssembly?&lt;/h2&gt;
&lt;p&gt;WebAssembly is a binary instruction format designed as a portable compilation target for high-level programming languages like C, C++, Rust, and others. It aims to provide efficient and secure execution of code on web browsers by allowing developers to compile their applications to a bytecode format that can be executed in a sandboxed environment. This bytecode can be executed at near-native speeds, providing performance improvements over traditional JavaScript-based web applications.&lt;/p&gt;
&lt;h2 id=&quot;how-webassembly-affects-web-app-development&quot;&gt;How WebAssembly Affects Web App Development&lt;/h2&gt;
&lt;h3 id=&quot;1-performance-boost&quot;&gt;1. Performance Boost&lt;/h3&gt;
&lt;p&gt;WebAssembly allows developers to write code that executes faster than equivalent JavaScript code. This speed improvement is crucial for applications that require heavy computations or real-time interactivity, such as games or complex simulations.&lt;/p&gt;
&lt;h3 id=&quot;2-language-diversity&quot;&gt;2. Language Diversity&lt;/h3&gt;
&lt;p&gt;With WebAssembly, developers are not limited to using just JavaScript for web development. They can choose languages they are already familiar with, such as C#, C++, or Rust, and compile their code to WebAssembly, opening up opportunities for code reuse and cross-platform development.&lt;/p&gt;
&lt;h3 id=&quot;3-code-security&quot;&gt;3. Code Security&lt;/h3&gt;
&lt;p&gt;WebAssembly code runs in a sandboxed environment, which enhances security by preventing direct access to browser internals. This isolation helps in mitigating security vulnerabilities and providing a safer user experience.&lt;/p&gt;
&lt;h3 id=&quot;4-cross-platform-compatibility&quot;&gt;4. Cross-Platform Compatibility&lt;/h3&gt;
&lt;p&gt;WebAssembly is designed to work across different browsers and platforms. This compatibility ensures that applications built with WebAssembly will run consistently regardless of the user&amp;#39;s chosen browser.&lt;/p&gt;
&lt;h3 id=&quot;5-enhanced-web-app-capabilities&quot;&gt;5. Enhanced Web App Capabilities&lt;/h3&gt;
&lt;p&gt;WebAssembly enables web applications to handle complex tasks and computations that were previously impractical in the browser. This opens doors for building advanced applications like video and image editing tools directly in the browser.&lt;/p&gt;
&lt;h2 id=&quot;building-an-e-commerce-application-with-c-and-net-core-using-webassembly&quot;&gt;Building an E-commerce Application with C# and .NET Core using WebAssembly&lt;/h2&gt;
&lt;p&gt;Let&amp;#39;s walk through an example of building a simple e-commerce application using C# and .NET Core with WebAssembly.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Setup&lt;/strong&gt;: Create a new Blazor WebAssembly project using the .NET CLI.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;dotnet &lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;hljs-type&quot;&gt;blazorwasm&lt;/span&gt; -n ECommerceApp
cd ECommerceApp
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Define Models&lt;/strong&gt;: Create C# classes to define the data models for your e-commerce application, such as &lt;code&gt;Product&lt;/code&gt; and &lt;code&gt;Cart&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code class=&quot;lang-csharp&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;Product&lt;/span&gt;
{
    &lt;span class=&quot;hljs-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;int&lt;/span&gt; Id { &lt;span class=&quot;hljs-keyword&quot;&gt;get&lt;/span&gt;; &lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt;; }
    &lt;span class=&quot;hljs-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;string&lt;/span&gt; Name { &lt;span class=&quot;hljs-keyword&quot;&gt;get&lt;/span&gt;; &lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt;; }
    &lt;span class=&quot;hljs-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;decimal&lt;/span&gt; Price { &lt;span class=&quot;hljs-keyword&quot;&gt;get&lt;/span&gt;; &lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt;; }
}

&lt;span class=&quot;hljs-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;CartItem&lt;/span&gt;
{
    &lt;span class=&quot;hljs-keyword&quot;&gt;public&lt;/span&gt; Product Product { &lt;span class=&quot;hljs-keyword&quot;&gt;get&lt;/span&gt;; &lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt;; }
    &lt;span class=&quot;hljs-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;int&lt;/span&gt; Quantity { &lt;span class=&quot;hljs-keyword&quot;&gt;get&lt;/span&gt;; &lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt;; }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Create Components&lt;/strong&gt;: Build Blazor components to display products and manage the shopping cart.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code class=&quot;lang-csharp&quot;&gt;&lt;span class=&quot;hljs-meta&quot;&gt;@page&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;/&quot;&lt;/span&gt;

&amp;lt;h3&amp;gt;Products&amp;lt;/h3&amp;gt;
&lt;span class=&quot;hljs-meta&quot;&gt;@foreach&lt;/span&gt; (&lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;/span&gt; product &lt;span class=&quot;hljs-keyword&quot;&gt;in&lt;/span&gt; products)
{
    &amp;lt;div&amp;gt;
        &amp;lt;h4&amp;gt;&lt;span class=&quot;hljs-meta&quot;&gt;@product&lt;/span&gt;.Name&amp;lt;/h4&amp;gt;
        &amp;lt;p&amp;gt;&lt;span class=&quot;hljs-meta&quot;&gt;@product&lt;/span&gt;.Price&amp;lt;/p&amp;gt;
        &amp;lt;button &lt;span class=&quot;hljs-meta&quot;&gt;@onclick&lt;/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;() =&amp;gt; AddToCart(product)&quot;&lt;/span&gt;&amp;gt;Add to Cart&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
}

&amp;lt;h3&amp;gt;Shopping Cart&amp;lt;/h3&amp;gt;
&lt;span class=&quot;hljs-meta&quot;&gt;@foreach&lt;/span&gt; (&lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;/span&gt; item &lt;span class=&quot;hljs-keyword&quot;&gt;in&lt;/span&gt; cart)
{
    &amp;lt;div&amp;gt;
        &amp;lt;h4&amp;gt;&lt;span class=&quot;hljs-meta&quot;&gt;@item&lt;/span&gt;.Product.Name&amp;lt;/h4&amp;gt;
        &amp;lt;p&amp;gt;Quantity: &lt;span class=&quot;hljs-meta&quot;&gt;@item&lt;/span&gt;.Quantity&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
}

&lt;span class=&quot;hljs-meta&quot;&gt;@code&lt;/span&gt; {
    &lt;span class=&quot;hljs-built_in&quot;&gt;List&lt;/span&gt;&amp;lt;Product&amp;gt; products = &lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;hljs-built_in&quot;&gt;List&lt;/span&gt;&amp;lt;Product&amp;gt;
    {
        &lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; Product { Id = &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, Name = &lt;span class=&quot;hljs-string&quot;&gt;&quot;Product 1&quot;&lt;/span&gt;, Price = &lt;span class=&quot;hljs-number&quot;&gt;10.99&lt;/span&gt;m },
        &lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; Product { Id = &lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;, Name = &lt;span class=&quot;hljs-string&quot;&gt;&quot;Product 2&quot;&lt;/span&gt;, Price = &lt;span class=&quot;hljs-number&quot;&gt;19.99&lt;/span&gt;m }
    };

    &lt;span class=&quot;hljs-built_in&quot;&gt;List&lt;/span&gt;&amp;lt;CartItem&amp;gt; cart = &lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;hljs-built_in&quot;&gt;List&lt;/span&gt;&amp;lt;CartItem&amp;gt;();

    &lt;span class=&quot;hljs-keyword&quot;&gt;void&lt;/span&gt; AddToCart(Product product)
    {
        &lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;/span&gt; existingItem = cart.FirstOrDefault(item =&amp;gt; item.Product.Id == product.Id);
        &lt;span class=&quot;hljs-keyword&quot;&gt;if&lt;/span&gt; (existingItem != &lt;span class=&quot;hljs-keyword&quot;&gt;null&lt;/span&gt;)
        {
            existingItem.Quantity++;
        }
        &lt;span class=&quot;hljs-keyword&quot;&gt;else&lt;/span&gt;
        {
            cart.Add(&lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; CartItem { Product = product, Quantity = &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt; });
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Run the App&lt;/strong&gt;: Build and run the application to see your e-commerce app in action.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;dotnet build
dotnet &lt;span class=&quot;hljs-keyword&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;bash&quot;&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Access the app in your browser, and you&amp;#39;ll be able to view products and add them to the shopping cart.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;WebAssembly is a game-changer for web application development. It introduces performance improvements, language diversity, and enhanced capabilities to web apps. The example of building an e-commerce application with C# and .NET Core using WebAssembly showcases how developers can leverage this technology to create efficient and feature-rich web applications. As WebAssembly continues to evolve and gain wider adoption, we can expect it to reshape the landscape of web development.&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/2775401860308709937/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/overview-of-webassembly.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/2775401860308709937'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/2775401860308709937'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/overview-of-webassembly.html' title='Overview of WebAssembly'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-6118106214767507545</id><published>2023-08-27T15:43:00.001+05:30</published><updated>2023-08-27T15:43:28.200+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term=".net"/><category scheme="http://www.blogger.com/atom/ns#" term=".net core"/><category scheme="http://www.blogger.com/atom/ns#" term="blazor"/><category scheme="http://www.blogger.com/atom/ns#" term="browser"/><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="client"/><category scheme="http://www.blogger.com/atom/ns#" term="dotnet"/><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="sandbox"/><category scheme="http://www.blogger.com/atom/ns#" term="secure sandbox"/><category scheme="http://www.blogger.com/atom/ns#" term="server"/><category scheme="http://www.blogger.com/atom/ns#" term="webassembly"/><title type='text'>Introduction to Blazor</title><content type='html'>&lt;h1 id=&quot;introduction-to-blazor-building-web-apps-with-c&quot;&gt;Introduction to Blazor with C#&lt;/h1&gt;
&lt;p&gt;Blazor is a modern web framework developed by Microsoft that allows developers to
  &lt;ol&gt;&lt;li&gt;Build interactive web applications using C# and .NET instead of traditional web technologies like JavaScript.&lt;/li&gt;
  &lt;li&gt;Blazor enables you to create web applications using the same language and tools you use to build other .NET applications, such as desktop and mobile applications. &lt;/li&gt;&lt;li&gt;It provides a way to write client-side code that runs directly in the browser while leveraging the power of C# and the .NET runtime.&lt;/li&gt;&lt;/ol&gt;
    &lt;/p&gt;
&lt;h2 id=&quot;how-blazor-works&quot;&gt;How Blazor Works&lt;/h2&gt;
&lt;p&gt;Blazor offers two hosting models: Blazor WebAssembly and Blazor Server.&lt;/p&gt;
&lt;h3 id=&quot;blazor-webassembly&quot;&gt;Blazor WebAssembly&lt;/h3&gt;
&lt;p&gt;In the WebAssembly hosting model, the Blazor application is compiled into WebAssembly bytecode, which is a binary instruction format designed for safe and efficient execution in web browsers. This bytecode is downloaded by the browser and executed directly in a secure sandbox environment. The application communicates with the server only during initial download and for fetching data, making it possible to build fully client-side web applications.&lt;/p&gt;
&lt;h3 id=&quot;blazor-server&quot;&gt;Blazor Server&lt;/h3&gt;
&lt;p&gt;In the Blazor Server hosting model, the application&amp;#39;s UI components and logic run on the server, while a lightweight JavaScript client handles user interactions and UI updates. Communication between the client and the server is achieved through SignalR, a real-time communication library. This model allows developers to build responsive and dynamic web applications while maintaining a strong connection to the server.&lt;/p&gt;
&lt;h2 id=&quot;advantages-of-blazor&quot;&gt;Advantages of Blazor&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Single Language&lt;/strong&gt;: Developers can use C# for both client-side and server-side development, which reduces the need to switch between different programming languages.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Code Sharing&lt;/strong&gt;: Blazor allows code sharing between client and server components, promoting code reuse and consistent behavior.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rich Ecosystem&lt;/strong&gt;: Blazor benefits from the existing .NET ecosystem, including libraries, tools, and developer expertise.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Type Safety&lt;/strong&gt;: Blazor leverages the static typing of C# to catch errors at compile time, reducing runtime issues.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Debugging&lt;/strong&gt;: Developers can use familiar debugging tools to debug both client-side and server-side code in one go.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Performance&lt;/strong&gt;: Blazor applications are optimized for performance, and WebAssembly execution can be highly efficient.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;the-future-of-blazor&quot;&gt;The Future of Blazor&lt;/h2&gt;
&lt;p&gt;Blazor has gained significant attention and adoption in the developer community due to its unique approach to web development. Microsoft continues to invest in Blazor, adding features, improving performance, and expanding its capabilities. As a result, the future of Blazor looks promising, and it is likely to become an even more viable option for building a wide range of web applications.&lt;/p&gt;
&lt;h2 id=&quot;hello-world-example-in-blazor&quot;&gt;Hello World Example in Blazor&lt;/h2&gt;
&lt;p&gt;Here&amp;#39;s a simple &amp;quot;Hello World&amp;quot; example using Blazor WebAssembly:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create a new Blazor WebAssembly project using the .NET CLI:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;dotnet &lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;hljs-type&quot;&gt;blazorwasm&lt;/span&gt; -n HelloWorldBlazor
cd HelloWorldBlazor
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;Open the &lt;code&gt;Pages/Index.razor&lt;/code&gt; file and replace its contents with:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code class=&quot;lang-csharp&quot;&gt;&lt;span class=&quot;hljs-meta&quot;&gt;@page&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;/&quot;&lt;/span&gt;
&lt;span class=&quot;hljs-variable&quot;&gt;&amp;lt;h3&amp;gt;&lt;/span&gt;Hello Blazor World!&lt;span class=&quot;hljs-variable&quot;&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
&lt;span class=&quot;hljs-variable&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;This is a simple Blazor WebAssembly application.&lt;span class=&quot;hljs-variable&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;Build and run the application:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;dotnet build
dotnet &lt;span class=&quot;hljs-keyword&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;bash&quot;&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The application will start, and you can access it by navigating to the provided URL in your web browser. You should see the &amp;quot;Hello Blazor World!&amp;quot; message displayed on the page.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Blazor is a revolutionary web framework that enables developers to build web applications using C# and .NET technologies. With its various hosting models, code sharing capabilities, and performance optimizations, Blazor offers a compelling alternative to traditional JavaScript-based web development. As Microsoft continues to enhance and develop Blazor, it is poised to play a significant role in the future of web development.&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/6118106214767507545/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/introduction-to-blazor.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/6118106214767507545'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/6118106214767507545'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/introduction-to-blazor.html' title='Introduction to Blazor'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-3767891886079986809</id><published>2023-08-25T10:43:00.002+05:30</published><updated>2023-08-25T10:43:21.934+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="attack"/><category scheme="http://www.blogger.com/atom/ns#" term="ef"/><category scheme="http://www.blogger.com/atom/ns#" term="efcore"/><category scheme="http://www.blogger.com/atom/ns#" term="entity framework core"/><category scheme="http://www.blogger.com/atom/ns#" term="filter"/><category scheme="http://www.blogger.com/atom/ns#" term="linq"/><category scheme="http://www.blogger.com/atom/ns#" term="linq to sql"/><category scheme="http://www.blogger.com/atom/ns#" term="manipulation"/><category scheme="http://www.blogger.com/atom/ns#" term="mitigation"/><category scheme="http://www.blogger.com/atom/ns#" term="owasp"/><category scheme="http://www.blogger.com/atom/ns#" term="parameter"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="sql injection"/><category scheme="http://www.blogger.com/atom/ns#" term="sql query"/><category scheme="http://www.blogger.com/atom/ns#" term="threat"/><category scheme="http://www.blogger.com/atom/ns#" term="vulnerability"/><title type='text'>Mitigation of SQL Injection attack in EF core</title><content type='html'>&lt;h2 style=&quot;text-align: left;&quot;&gt;Mitigating SQL Injection Attacks with Entity Framework Core&lt;/h2&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;Introduction:&amp;nbsp;&lt;/h3&gt;&lt;p&gt;SQL injection is a serious security vulnerability that occurs when an attacker manipulates input data to execute unauthorized SQL queries. Entity Framework Core (EF Core) is an Object-Relational Mapping (ORM) framework that provides built-in safeguards against SQL injection attacks. This article explores how EF Core helps prevent SQL injection, discusses common attack vectors, and provides code samples to illustrate the concepts.&lt;/p&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;Understanding SQL Injection:&lt;/h3&gt;&lt;p&gt;&amp;nbsp;SQL injection occurs when untrusted user input is directly concatenated into SQL queries. Attackers exploit this vulnerability by injecting malicious SQL code, leading to data breaches, unauthorized access, and more.&lt;/p&gt;
&lt;p&gt;How EF Core Helps Prevent SQL Injection:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Parameterized Queries: EF Core automatically generates parameterized queries. Instead of concatenating values directly into SQL statements, it binds input values as parameters. This prevents attackers from injecting malicious code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;LINQ-to-Entities: EF Core encourages the use of LINQ queries, where queries are expressed using language constructs. These queries are automatically translated into parameterized SQL queries by EF Core, further reducing the risk of injection.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Common Attack Vectors and Mitigation:&lt;/p&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simple SQL Injection:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Attack Vector:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;string query = &quot;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; * &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;Users&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; Username = &lt;span class=&quot;hljs-string&quot;&gt;&#39;&quot; + userInput + &quot;&#39;&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&quot;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Mitigation (EF Core Approach):&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;lang-csharp&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;/span&gt; user = &lt;span class=&quot;hljs-keyword&quot;&gt;await&lt;/span&gt; context.Users.FirstOrDefaultAsync(&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-params&quot;&gt;u&lt;/span&gt; =&amp;gt;&lt;/span&gt; u.Username == userInput);
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Union-Based Injection:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Attack Vector:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;string query = &quot;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; * &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Products &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;Id&lt;/span&gt; = &lt;span class=&quot;hljs-string&quot;&gt;&quot; + userInput + &quot;&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;UNION&lt;/span&gt; ALL &lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;NULL&lt;/span&gt;, &lt;span class=&quot;hljs-literal&quot;&gt;NULL&lt;/span&gt;, @@&lt;span class=&quot;hljs-keyword&quot;&gt;version&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;--&quot;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Mitigation (EF Core Approach):&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;lang-csharp&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;/span&gt; productId = Int32.Parse(userInput);
&lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;/span&gt; products = &lt;span class=&quot;hljs-keyword&quot;&gt;await&lt;/span&gt; context.Products.FromSqlInterpolated(&lt;span class=&quot;hljs-string&quot;&gt;$&quot;SELECT * FROM Products WHERE Id = &lt;span class=&quot;hljs-subst&quot;&gt;{productId}&lt;/span&gt;&quot;&lt;/span&gt;);
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Time-Based Blind Injection:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Attack Vector:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;string query = &quot;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; * &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; Orders &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;Status&lt;/span&gt; = &lt;span class=&quot;hljs-string&quot;&gt;&#39;Shipped&#39;&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;AND&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;=(&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;COUNT&lt;/span&gt;(*) &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; sysobjects &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;name&lt;/span&gt; = &lt;span class=&quot;hljs-string&quot;&gt;&#39;tablename&#39;&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;AND&lt;/span&gt; user_name(&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;)=username)&lt;span class=&quot;hljs-string&quot;&gt;&quot;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Mitigation (EF Core Approach):&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;lang-csharp&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;/span&gt; status = &lt;span class=&quot;hljs-string&quot;&gt;&quot;Shipped&quot;&lt;/span&gt;;
&lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;/span&gt; orders = &lt;span class=&quot;hljs-keyword&quot;&gt;await&lt;/span&gt; context.Orders.Where(&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-params&quot;&gt;o&lt;/span&gt; =&amp;gt;&lt;/span&gt; o.Status == status).ToListAsync();
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;Sample Code&amp;nbsp;&lt;/h3&gt;&lt;p&gt;Using EF Core to Prevent Injection:
Assuming a simple &lt;code&gt;User&lt;/code&gt; entity and a &lt;code&gt;DbContext&lt;/code&gt;, here&#39;s how you can use EF Core to prevent SQL injection:&lt;/p&gt;
&lt;pre style=&quot;text-align: left;&quot;&gt;&lt;code class=&quot;lang-csharp&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;User&lt;/span&gt;
{
    &lt;span class=&quot;hljs-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;int&lt;/span&gt; Id { &lt;span class=&quot;hljs-keyword&quot;&gt;get&lt;/span&gt;; &lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt;; }
    &lt;span class=&quot;hljs-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;string&lt;/span&gt; Username { &lt;span class=&quot;hljs-keyword&quot;&gt;get&lt;/span&gt;; &lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt;; }
    &lt;span class=&quot;hljs-comment&quot;&gt;// Other properties...&lt;/span&gt;
}

&lt;span class=&quot;hljs-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;AppDbContext&lt;/span&gt; : &lt;span class=&quot;hljs-title&quot;&gt;DbContext&lt;/span&gt;
{
    &lt;span class=&quot;hljs-keyword&quot;&gt;public&lt;/span&gt; DbSet&amp;lt;User&amp;gt; Users { &lt;span class=&quot;hljs-keyword&quot;&gt;get&lt;/span&gt;; &lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt;; }
    &lt;span class=&quot;hljs-comment&quot;&gt;// Other DbSet properties...&lt;/span&gt;

    &lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;OnConfiguring&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;DbContextOptionsBuilder optionsBuilder&lt;/span&gt;)
    &lt;/span&gt;{
        optionsBuilder.UseSqlServer(&lt;span class=&quot;hljs-string&quot;&gt;&quot;your_connection_string_here&quot;&lt;/span&gt;);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;Conclusion:&amp;nbsp;&lt;/h3&gt;&lt;p&gt;Entity Framework Core provides strong safeguards against SQL injection attacks by utilizing parameterized queries and LINQ-to-Entities. Developers can rely on these features to mitigate the risks associated with direct input concatenation. By adopting EF Core best practices, developers can build more secure applications that protect against SQL injection vulnerabilities.&lt;/p&gt;

</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/3767891886079986809/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/mitigation-of-sql-injection-attack-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/3767891886079986809'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/3767891886079986809'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/mitigation-of-sql-injection-attack-in.html' title='Mitigation of SQL Injection attack in EF core'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-4102767547096432597</id><published>2023-08-25T10:33:00.006+05:30</published><updated>2023-08-25T10:33:56.558+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term=".net core"/><category scheme="http://www.blogger.com/atom/ns#" term="app service"/><category scheme="http://www.blogger.com/atom/ns#" term="attack"/><category scheme="http://www.blogger.com/atom/ns#" term="azure"/><category scheme="http://www.blogger.com/atom/ns#" term="data"/><category scheme="http://www.blogger.com/atom/ns#" term="dotnet core"/><category scheme="http://www.blogger.com/atom/ns#" term="filtering"/><category scheme="http://www.blogger.com/atom/ns#" term="iis"/><category scheme="http://www.blogger.com/atom/ns#" term="middleware"/><category scheme="http://www.blogger.com/atom/ns#" term="owasp"/><category scheme="http://www.blogger.com/atom/ns#" term="owin"/><category scheme="http://www.blogger.com/atom/ns#" term="payload"/><category scheme="http://www.blogger.com/atom/ns#" term="request"/><category scheme="http://www.blogger.com/atom/ns#" term="REST"/><category scheme="http://www.blogger.com/atom/ns#" term="rest api"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><category scheme="http://www.blogger.com/atom/ns#" term="vulnerability"/><category scheme="http://www.blogger.com/atom/ns#" term="web security"/><category scheme="http://www.blogger.com/atom/ns#" term="webapi"/><title type='text'>Securing application from vulnerable inputs through middleware in dotnet core</title><content type='html'>
&lt;p&gt;Securing Applications with ASP.NET Core OWIN Middleware Against Payload Attacks&lt;/p&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;Introduction:&amp;nbsp;&lt;/h3&gt;&lt;p&gt;Cybersecurity is a crucial aspect of modern application development. One area of concern is preventing attacks that exploit vulnerabilities in request payloads. This article explores how to use ASP.NET Core OWIN middleware to enhance the security of your applications by addressing payload-based attacks.&lt;/p&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;Vulnerability:&amp;nbsp;&lt;/h3&gt;&lt;p&gt;Payload Attacks
Payload attacks involve sending malicious data in the request payload to exploit vulnerabilities. These attacks can lead to various security breaches, including data exposure, injection attacks, and remote code execution.&lt;/p&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;Using OWIN Middleware:&amp;nbsp;&lt;/h3&gt;&lt;p&gt;ASP.NET Core provides the OWIN (Open Web Interface for .NET) middleware pipeline, which can be customized to intercept and process requests before they reach the application&#39;s core logic. This provides an opportunity to implement security measures.&lt;/p&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;Sample Code&lt;/h3&gt;&lt;p&gt;Implementing Payload Inspection Middleware:
Here&#39;s an example of implementing a simple OWIN middleware that inspects incoming request payloads for potential malicious content:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;lang-csharp&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;using&lt;/span&gt; Microsoft.AspNetCore.Builder;
&lt;span class=&quot;hljs-keyword&quot;&gt;using&lt;/span&gt; Microsoft.AspNetCore.Http;
&lt;span class=&quot;hljs-keyword&quot;&gt;using&lt;/span&gt; System.IO;
&lt;span class=&quot;hljs-keyword&quot;&gt;using&lt;/span&gt; System.Text;
&lt;span class=&quot;hljs-keyword&quot;&gt;using&lt;/span&gt; System.Threading.Tasks;

&lt;span class=&quot;hljs-keyword&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;PayloadSecurityMiddleware&lt;/span&gt;
{
    &lt;span class=&quot;hljs-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;PayloadInspectionMiddleware&lt;/span&gt;
    {
        &lt;span class=&quot;hljs-keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;readonly&lt;/span&gt; RequestDelegate _next;

        &lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;PayloadInspectionMiddleware&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;RequestDelegate next&lt;/span&gt;)
        &lt;/span&gt;{
            _next = next;
        }

        &lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;async&lt;/span&gt; Task &lt;span class=&quot;hljs-title&quot;&gt;Invoke&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;HttpContext context&lt;/span&gt;)
        &lt;/span&gt;{
            &lt;span class=&quot;hljs-comment&quot;&gt;// Read the request payload&lt;/span&gt;
            &lt;span class=&quot;hljs-keyword&quot;&gt;string&lt;/span&gt; payload = &lt;span class=&quot;hljs-keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; StreamReader(context.Request.Body, Encoding.UTF8).ReadToEndAsync();

            &lt;span class=&quot;hljs-comment&quot;&gt;// Perform payload inspection for potential threats&lt;/span&gt;
            &lt;span class=&quot;hljs-keyword&quot;&gt;if&lt;/span&gt; (HasMaliciousContent(payload))
            {
                context.Response.StatusCode = &lt;span class=&quot;hljs-number&quot;&gt;400&lt;/span&gt;;
                &lt;span class=&quot;hljs-keyword&quot;&gt;await&lt;/span&gt; context.Response.WriteAsync(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Malicious payload detected.&quot;&lt;/span&gt;);
                &lt;span class=&quot;hljs-keyword&quot;&gt;return&lt;/span&gt;;
            }

            &lt;span class=&quot;hljs-keyword&quot;&gt;await&lt;/span&gt; _next(context);
        }

        &lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;HasMaliciousContent&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;string&lt;/span&gt; payload&lt;/span&gt;)
        &lt;/span&gt;{
            &lt;span class=&quot;hljs-comment&quot;&gt;// Implement your payload inspection logic here&lt;/span&gt;
            &lt;span class=&quot;hljs-comment&quot;&gt;// Return true if malicious content is detected&lt;/span&gt;
            &lt;span class=&quot;hljs-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;false&lt;/span&gt;;
        }
    }

    &lt;span class=&quot;hljs-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;PayloadInspectionMiddlewareExtensions&lt;/span&gt;
    {
        &lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;static&lt;/span&gt; IApplicationBuilder &lt;span class=&quot;hljs-title&quot;&gt;UsePayloadInspectionMiddleware&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;this&lt;/span&gt; IApplicationBuilder builder&lt;/span&gt;)
        &lt;/span&gt;{
            &lt;span class=&quot;hljs-keyword&quot;&gt;return&lt;/span&gt; builder.UseMiddleware&amp;lt;PayloadInspectionMiddleware&amp;gt;();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In this example, the &lt;code&gt;PayloadInspectionMiddleware&lt;/code&gt; reads the request payload and performs a basic inspection. You should replace the &lt;code&gt;HasMaliciousContent&lt;/code&gt; method with actual logic to detect malicious content patterns.&lt;/p&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;Conclusion:&amp;nbsp;&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;By leveraging ASP.NET Core OWIN middleware, developers can implement custom security measures to prevent payload-based attacks. This article covered the basics of using middleware for payload inspection, but further customization and integration with security libraries are recommended to create a comprehensive defense strategy against various payload attacks.&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/4102767547096432597/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/securing-application-from-vulnerable.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/4102767547096432597'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/4102767547096432597'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/securing-application-from-vulnerable.html' title='Securing application from vulnerable inputs through middleware in dotnet core'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-4236839134958754474</id><published>2023-08-24T10:58:00.001+05:30</published><updated>2023-08-24T10:58:07.395+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="blob"/><category scheme="http://www.blogger.com/atom/ns#" term="csv"/><category scheme="http://www.blogger.com/atom/ns#" term="download"/><category scheme="http://www.blogger.com/atom/ns#" term="fetch"/><category scheme="http://www.blogger.com/atom/ns#" term="fetch api"/><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="rest api"/><title type='text'>Download CSV file using JavaScript fetch API</title><content type='html'>
&lt;p&gt;&lt;strong&gt;Downloading a CSV File from an API Using JavaScript Fetch API: A Step-by-Step Guide&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Introduction:&lt;/strong&gt;
Downloading files from an API is a common task in web development. This article walks you through the process of downloading a CSV file from an API using the Fetch API in JavaScript. We&amp;#39;ll cover the basics of making API requests and handling file downloads, complete with a sample code snippet.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Prerequisites:&lt;/strong&gt;
Ensure you have a basic understanding of JavaScript and web APIs. No additional libraries are required for this tutorial.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 1: Creating the HTML Structure:&lt;/strong&gt;
Start by creating a simple HTML structure that includes a button to initiate the file download.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;lang-html&quot;&gt;&lt;span class=&quot;hljs-meta&quot;&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;html&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;lang&lt;/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;en&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;head&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;meta&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;charset&lt;/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;UTF-8&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;meta&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name&lt;/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;viewport&quot;&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;content&lt;/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;width=device-width, initial-scale=1.0&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;title&lt;/span&gt;&amp;gt;&lt;/span&gt;CSV File Download&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;title&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;head&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;body&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;button&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;downloadButton&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;Download CSV&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;button&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;&lt;span class=&quot;hljs-name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;script.js&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;undefined&quot;&gt;&lt;/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;body&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;hljs-tag&quot;&gt;&amp;lt;/&lt;span class=&quot;hljs-name&quot;&gt;html&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Step 2: Writing JavaScript Code:&lt;/strong&gt;
Create a JavaScript file named &lt;code&gt;script.js&lt;/code&gt; and write the code to download the CSV file using the Fetch API.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;lang-javascript&quot;&gt;&lt;span class=&quot;hljs-comment&quot;&gt;// Select the download button&lt;/span&gt;
&lt;span class=&quot;hljs-keyword&quot;&gt;const&lt;/span&gt; downloadButton = &lt;span class=&quot;hljs-built_in&quot;&gt;document&lt;/span&gt;.getElementById(&lt;span class=&quot;hljs-string&quot;&gt;&quot;downloadButton&quot;&lt;/span&gt;);

&lt;span class=&quot;hljs-comment&quot;&gt;// Define the API URL for the CSV file&lt;/span&gt;
&lt;span class=&quot;hljs-keyword&quot;&gt;const&lt;/span&gt; apiUrl = &lt;span class=&quot;hljs-string&quot;&gt;&quot;https://api.example.com/download/csv&quot;&lt;/span&gt;;

&lt;span class=&quot;hljs-comment&quot;&gt;// Function to trigger file download&lt;/span&gt;
&lt;span class=&quot;hljs-keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;downloadCSV&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;{
    &lt;span class=&quot;hljs-keyword&quot;&gt;try&lt;/span&gt; {
        &lt;span class=&quot;hljs-keyword&quot;&gt;const&lt;/span&gt; response = &lt;span class=&quot;hljs-keyword&quot;&gt;await&lt;/span&gt; fetch(apiUrl);
        &lt;span class=&quot;hljs-keyword&quot;&gt;const&lt;/span&gt; blob = &lt;span class=&quot;hljs-keyword&quot;&gt;await&lt;/span&gt; response.blob();

        &lt;span class=&quot;hljs-comment&quot;&gt;// Create a URL for the blob&lt;/span&gt;
        &lt;span class=&quot;hljs-keyword&quot;&gt;const&lt;/span&gt; blobUrl = URL.createObjectURL(blob);

        &lt;span class=&quot;hljs-comment&quot;&gt;// Create a temporary anchor element&lt;/span&gt;
        &lt;span class=&quot;hljs-keyword&quot;&gt;const&lt;/span&gt; link = &lt;span class=&quot;hljs-built_in&quot;&gt;document&lt;/span&gt;.createElement(&lt;span class=&quot;hljs-string&quot;&gt;&quot;a&quot;&lt;/span&gt;);
        link.href = blobUrl;
        link.download = &lt;span class=&quot;hljs-string&quot;&gt;&quot;data.csv&quot;&lt;/span&gt;;
        link.style.display = &lt;span class=&quot;hljs-string&quot;&gt;&quot;none&quot;&lt;/span&gt;;

        &lt;span class=&quot;hljs-comment&quot;&gt;// Append the anchor element to the body and click it&lt;/span&gt;
        &lt;span class=&quot;hljs-built_in&quot;&gt;document&lt;/span&gt;.body.appendChild(link);
        link.click();

        &lt;span class=&quot;hljs-comment&quot;&gt;// Clean up&lt;/span&gt;
        &lt;span class=&quot;hljs-built_in&quot;&gt;document&lt;/span&gt;.body.removeChild(link);
        URL.revokeObjectURL(blobUrl);
    } &lt;span class=&quot;hljs-keyword&quot;&gt;catch&lt;/span&gt; (error) {
        &lt;span class=&quot;hljs-built_in&quot;&gt;console&lt;/span&gt;.error(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Error downloading CSV:&quot;&lt;/span&gt;, error);
    }
}

&lt;span class=&quot;hljs-comment&quot;&gt;// Attach click event listener to the button&lt;/span&gt;
downloadButton.addEventListener(&lt;span class=&quot;hljs-string&quot;&gt;&quot;click&quot;&lt;/span&gt;, downloadCSV);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Step 3: Explanation of the Code:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We select the download button element using &lt;code&gt;document.getElementById&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Inside the &lt;code&gt;downloadCSV&lt;/code&gt; function, we use the Fetch API to make a request to the API URL. We await the response and convert it to a &lt;code&gt;Blob&lt;/code&gt; object, which represents binary data.&lt;/li&gt;
&lt;li&gt;We create a URL for the &lt;code&gt;Blob&lt;/code&gt; using &lt;code&gt;URL.createObjectURL&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A temporary anchor (&lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt;) element is created and configured to download the CSV file. We set its &lt;code&gt;href&lt;/code&gt; to the blob URL and &lt;code&gt;download&lt;/code&gt; attribute to specify the filename.&lt;/li&gt;
&lt;li&gt;The anchor element is appended to the document body and programmatically clicked to initiate the download.&lt;/li&gt;
&lt;li&gt;Finally, the anchor element is removed, and the blob URL is revoked to free up resources.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Step 4: Testing the Code:&lt;/strong&gt;
Open the HTML file in a web browser. Clicking the &amp;quot;Download CSV&amp;quot; button will trigger the API request and download the CSV file to the user&amp;#39;s device.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;
Using the Fetch API, you can easily download files from APIs in your web applications. This step-by-step guide demonstrated how to download a CSV file using the Fetch API, providing a seamless way to retrieve and save files from remote sources. Feel free to adapt this approach for different file types and use cases in your projects.&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/4236839134958754474/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/download-csv-file-using-javascript.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/4236839134958754474'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/4236839134958754474'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/download-csv-file-using-javascript.html' title='Download CSV file using JavaScript fetch API'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-3310190181606180221</id><published>2023-08-24T10:36:00.005+05:30</published><updated>2023-08-24T10:36:35.320+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="apache"/><category scheme="http://www.blogger.com/atom/ns#" term="backup"/><category scheme="http://www.blogger.com/atom/ns#" term="data migration"/><category scheme="http://www.blogger.com/atom/ns#" term="database"/><category scheme="http://www.blogger.com/atom/ns#" term="database migration"/><category scheme="http://www.blogger.com/atom/ns#" term="etl"/><category scheme="http://www.blogger.com/atom/ns#" term="mysql"/><category scheme="http://www.blogger.com/atom/ns#" term="mysqldump"/><category scheme="http://www.blogger.com/atom/ns#" term="mysqldump.exe"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="restore database"/><category scheme="http://www.blogger.com/atom/ns#" term="strategies"/><category scheme="http://www.blogger.com/atom/ns#" term="tools"/><title type='text'>Data Migration Strategies for MySQL databases</title><content type='html'>&lt;p&gt;&lt;strong&gt;Data Migration Strategies for MySQL Databases: An Overview of few Approaches&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Introduction:&lt;/strong&gt;
Data migration is a crucial aspect of database management, especially when transitioning from one MySQL database to another. It involves transferring data while ensuring its integrity, consistency, and availability. This article explores the challenges associated with data migration and provides detailed solutions along with sample code snippets.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Challenges in Data Migration:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Consistency:&lt;/strong&gt; Ensuring that data remains consistent during the migration process is critical. Any discrepancies or errors can lead to incorrect results and data loss.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Downtime:&lt;/strong&gt; Minimizing downtime is essential to maintain business continuity. Prolonged downtime can disrupt operations and affect user experience.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Schema Changes:&lt;/strong&gt; When migrating to a new database version, the schema might change. Adapting the data to fit the new schema while preserving relationships can be complex.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Volume:&lt;/strong&gt; Handling large data volumes requires efficient migration techniques to avoid performance bottlenecks and resource exhaustion.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Data Migration Strategies:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dump and Restore:&lt;/strong&gt;
This strategy involves exporting the data from the source database into a file (using tools like &lt;code&gt;mysqldump&lt;/code&gt;), transferring it to the target database, and then restoring it. While simple, it might not be suitable for large datasets due to longer downtime and performance impact.&lt;/p&gt;
&lt;p&gt;Sample code for exporting data:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;mysqldump -u username -&lt;span class=&quot;hljs-selector-tag&quot;&gt;p&lt;/span&gt; database_name &amp;gt; dump.sql
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Replication:&lt;/strong&gt;
MySQL replication allows real-time data synchronization between the source and target databases. This approach minimizes downtime and ensures consistency.&lt;/p&gt;
&lt;p&gt;Sample code for setting up replication:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;lang-sql&quot;&gt;&lt;span class=&quot;hljs-comment&quot;&gt;-- On source server&lt;/span&gt;
&lt;span class=&quot;hljs-keyword&quot;&gt;GRANT&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;REPLICATION&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;SLAVE&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;ON&lt;/span&gt; *.* &lt;span class=&quot;hljs-keyword&quot;&gt;TO&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&#39;replication_user&#39;&lt;/span&gt;@&lt;span class=&quot;hljs-string&quot;&gt;&#39;target_ip&#39;&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;IDENTIFIED&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;BY&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&#39;password&#39;&lt;/span&gt;;
&lt;span class=&quot;hljs-keyword&quot;&gt;FLUSH&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;PRIVILEGES&lt;/span&gt;;
&lt;span class=&quot;hljs-keyword&quot;&gt;FLUSH&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;TABLES&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;WITH&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;READ&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;LOCK&lt;/span&gt;;
&lt;span class=&quot;hljs-keyword&quot;&gt;SHOW&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;MASTER&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;STATUS&lt;/span&gt;;

&lt;span class=&quot;hljs-comment&quot;&gt;-- On target server&lt;/span&gt;
&lt;span class=&quot;hljs-keyword&quot;&gt;CHANGE&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;MASTER&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;TO&lt;/span&gt; MASTER_HOST=&lt;span class=&quot;hljs-string&quot;&gt;&#39;source_ip&#39;&lt;/span&gt;, MASTER_USER=&lt;span class=&quot;hljs-string&quot;&gt;&#39;replication_user&#39;&lt;/span&gt;, MASTER_PASSWORD=&lt;span class=&quot;hljs-string&quot;&gt;&#39;password&#39;&lt;/span&gt;, MASTER_LOG_FILE=&lt;span class=&quot;hljs-string&quot;&gt;&#39;bin_log_file&#39;&lt;/span&gt;, MASTER_LOG_POS=bin_log_position;
&lt;span class=&quot;hljs-keyword&quot;&gt;START&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;SLAVE&lt;/span&gt;;
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ETL (Extract, Transform, Load):&lt;/strong&gt;
ETL involves extracting data from the source, transforming it to fit the target schema, and loading it into the destination database. This is ideal for data transformations and filtering.&lt;/p&gt;
&lt;p&gt;Sample code using Python and MySQL Connector:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;lang-python&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;import&lt;/span&gt; mysql.connector

source_db = mysql.connector.connect(host=&lt;span class=&quot;hljs-string&quot;&gt;&#39;source_host&#39;&lt;/span&gt;, user=&lt;span class=&quot;hljs-string&quot;&gt;&#39;username&#39;&lt;/span&gt;, password=&lt;span class=&quot;hljs-string&quot;&gt;&#39;password&#39;&lt;/span&gt;, database=&lt;span class=&quot;hljs-string&quot;&gt;&#39;source_db&#39;&lt;/span&gt;)
target_db = mysql.connector.connect(host=&lt;span class=&quot;hljs-string&quot;&gt;&#39;target_host&#39;&lt;/span&gt;, user=&lt;span class=&quot;hljs-string&quot;&gt;&#39;username&#39;&lt;/span&gt;, password=&lt;span class=&quot;hljs-string&quot;&gt;&#39;password&#39;&lt;/span&gt;, database=&lt;span class=&quot;hljs-string&quot;&gt;&#39;target_db&#39;&lt;/span&gt;)

source_cursor = source_db.cursor()
target_cursor = target_db.cursor()

source_cursor.execute(&lt;span class=&quot;hljs-string&quot;&gt;&#39;SELECT * FROM source_table&#39;&lt;/span&gt;)
&lt;span class=&quot;hljs-keyword&quot;&gt;data&lt;/span&gt; = source_cursor.fetchall()

&lt;span class=&quot;hljs-keyword&quot;&gt;for&lt;/span&gt; row &lt;span class=&quot;hljs-built_in&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;data&lt;/span&gt;:
    # Transform &lt;span class=&quot;hljs-keyword&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;if&lt;/span&gt; needed
    target_cursor.execute(&lt;span class=&quot;hljs-string&quot;&gt;&#39;INSERT INTO target_table VALUES (%s, %s, %s)&#39;&lt;/span&gt;, row)

target_db.commit()
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;
Data migration is a critical phase in database management, requiring careful planning and execution. By understanding the challenges and implementing appropriate strategies like dump and restore, replication, or ETL, you can ensure a seamless transition while maintaining data integrity and minimizing downtime. Utilizing the sample code provided for each strategy will help you get started on your data migration journey.&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/3310190181606180221/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/data-migration-strategies-for-mysql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/3310190181606180221'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/3310190181606180221'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/data-migration-strategies-for-mysql.html' title='Data Migration Strategies for MySQL databases'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-3932874732146029179</id><published>2023-08-24T09:30:00.001+05:30</published><updated>2023-08-24T09:32:52.692+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="auto update"/><category scheme="http://www.blogger.com/atom/ns#" term="automation"/><category scheme="http://www.blogger.com/atom/ns#" term="browser"/><category scheme="http://www.blogger.com/atom/ns#" term="chrome"/><category scheme="http://www.blogger.com/atom/ns#" term="chrome test"/><category scheme="http://www.blogger.com/atom/ns#" term="chromedriver"/><category scheme="http://www.blogger.com/atom/ns#" term="google chrome"/><category scheme="http://www.blogger.com/atom/ns#" term="robot"/><category scheme="http://www.blogger.com/atom/ns#" term="robot framework"/><category scheme="http://www.blogger.com/atom/ns#" term="rpa"/><category scheme="http://www.blogger.com/atom/ns#" term="testing"/><category scheme="http://www.blogger.com/atom/ns#" term="upgrade"/><category scheme="http://www.blogger.com/atom/ns#" term="version"/><category scheme="http://www.blogger.com/atom/ns#" term="webdriver"/><title type='text'>Chrome for Testing: Browser Automation made easy</title><content type='html'>&lt;img src=&quot;https://wd.imgix.net/image/ZQjEes3OsyYCDLE5837FjNRQ1Gw2/Wn5kQQRVssFAHozIWDX3.svg&quot; alt=&quot;Chrome for Testing&quot; style=&quot; display: block;  margin-left: auto;  margin-right: auto;  width: 50%; height:50%&quot; /&gt;
&lt;h3 id=&quot;introduction&quot;&gt;&lt;br /&gt;&lt;/h3&gt;&lt;h3 id=&quot;introduction&quot;&gt;Introduction&lt;/h3&gt;
&lt;p&gt;Google Chrome for Testing is a new Chrome flavor that specifically targets web app testing and automation use cases.&lt;/p&gt;
&lt;h3 id=&quot;browser-and-driver-setup-and-maintenance&quot;&gt;Browser and Driver Setup and Maintenance&lt;/h3&gt;
&lt;p&gt;Setting up a browser testing environment is a difficult task, and it needs more effort to keep the browser and the chrome driver up-to-date and it is a top web developer / automation engineer&#39;s pain point&lt;/p&gt;
&lt;h3 id=&quot;the-auto-update&quot;&gt;The Auto-Update&lt;/h3&gt;
&lt;p&gt;One of Chrome’s most notable features is its ability to auto-update. This helps the users to keep their browsers up-to-date with the latest upgrades and be safe when they are online&lt;/p&gt;
&lt;p&gt;As a developer / automation engineer, running a suite of end-to-end tests requires the below aspects to be taken care of&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You want consistent, reproducible results across repeated test runs—but this may not happen if the browser executable or binary decides to update itself in between two runs.&lt;/li&gt;
&lt;li&gt;You want to pin a specific browser version and check that version number into your source code repository, so that you can check out old commits and branches and re-run the tests against the browser binary from that point in time.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The process of a browser that auto-updates creates compatibitlity with webdriver and there needs to be a manual intervention to address this.&lt;/p&gt;
&lt;h3 id=&quot;versioned-browser-binaries&quot;&gt;Versioned browser binaries&lt;/h3&gt;
&lt;p&gt;Google intentionally doesn’t make versioned Chrome downloads available, since users shouldn’t have to care about version numbers—they should always get updated to the latest version as soon as possible. This is great for users, but painful for developers needing to reproduce a bug report in an older Chrome version&lt;/p&gt;
&lt;p&gt;Due to the manual intervention and addressing of the version issue, there are flaws. &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;First, these Chromium binaries are not reliably available across all platforms. &lt;/li&gt;
&lt;li&gt;Second, they are built and published separately from the Chrome release process, making it impossible to map their versions back to real user-facing Chrome releases. &lt;/li&gt;
&lt;li&gt;Third, Chromium is different from Chrome&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;chrome-for-testing&quot;&gt;Chrome for Testing&lt;/h3&gt;
&lt;p&gt;Designed to solve these problems, Chrome for Testing is a dedicated flavor of Chrome targeting the testing use case, without auto-update, integrated into the Chrome release process, made available for every Chrome release. A versioned binary that’s as close to regular Chrome as possible without negatively affecting the testing use case.&lt;/p&gt;
&lt;p&gt;The difficulties we previously mentioned around finding a matching Chrome and ChromeDriver binary can be completely eliminated by integrating the ChromeDriver release process into the Chrome for Testing infrastructure. In addition to solving this user-facing pain point, this also aligns ChromeDriver releases with Chrome’s, and eliminates the manual ChromeDriver release process.&lt;/p&gt;

&lt;h3&gt;Conclusion&lt;/h3&gt;
The release of chrome for testing is a big boon for the developers and the automation engineers that helps in fixing the chrome and driver compatibilty across upgrades. Please read through the below link to learn more and to use the latest commands from google team
&lt;a href=&quot;https://developer.chrome.com/blog/chrome-for-testing/&quot; target=&quot;_blank&quot;&gt;Chrome Blog&lt;/a&gt;

&lt;h6&gt;Happy &amp;amp; Peaceful Testing !!!&lt;/h6&gt;</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/3932874732146029179/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/chrome-for-testing-browser-automation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/3932874732146029179'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/3932874732146029179'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/chrome-for-testing-browser-automation.html' title='Chrome for Testing: Browser Automation made easy'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-2122990472777291519</id><published>2023-08-23T10:44:00.008+05:30</published><updated>2023-08-23T10:44:57.286+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="alias"/><category scheme="http://www.blogger.com/atom/ns#" term="developer"/><category scheme="http://www.blogger.com/atom/ns#" term="developer productivity"/><category scheme="http://www.blogger.com/atom/ns#" term="git"/><category scheme="http://www.blogger.com/atom/ns#" term="git bash"/><category scheme="http://www.blogger.com/atom/ns#" term="git bash alias"/><category scheme="http://www.blogger.com/atom/ns#" term="gitbash"/><category scheme="http://www.blogger.com/atom/ns#" term="github"/><category scheme="http://www.blogger.com/atom/ns#" term="keystrokes"/><category scheme="http://www.blogger.com/atom/ns#" term="productivity"/><category scheme="http://www.blogger.com/atom/ns#" term="shortcuts"/><category scheme="http://www.blogger.com/atom/ns#" term="time management"/><category scheme="http://www.blogger.com/atom/ns#" term="time saving"/><category scheme="http://www.blogger.com/atom/ns#" term="useful commands"/><title type='text'>Git Bash Developer Productivity Tips</title><content type='html'>&lt;h1 id=&quot;boosting-productivity-with-custom-aliases-in-git-bash&quot;&gt;Boosting Productivity with Custom Aliases in Git Bash&lt;/h1&gt;
&lt;p&gt;As a developer, efficiency and productivity are paramount. One of the lesser-known gems in Git Bash is the ability to create custom aliases, which are shortcuts for commonly used Git commands or even more complex workflows. These aliases not only save keystrokes but also streamline your workflow, making version control tasks smoother and quicker. In this article, we&amp;#39;ll dive into the world of custom aliases, explore how to create them, and highlight their time-saving potential.&lt;/p&gt;
&lt;h2 id=&quot;what-are-custom-aliases-&quot;&gt;What are Custom Aliases?&lt;/h2&gt;
&lt;p&gt;Custom aliases in Git Bash are user-defined shortcuts for frequently used commands. These aliases can be as simple as abbreviations or even entire command sequences. They can encompass both Git-specific commands and regular shell commands.&lt;/p&gt;
&lt;h2 id=&quot;creating-custom-aliases&quot;&gt;Creating Custom Aliases&lt;/h2&gt;
&lt;p&gt;To create custom aliases, you need to modify your Git configuration. You can define aliases in two scopes: 
&lt;ol&gt;&lt;li&gt;local (for a specific repository) &lt;/li&gt;&lt;li&gt; global (for all repositories on your system)&lt;/li&gt;&lt;/ol&gt; Here&amp;#39;s how you can set up custom aliases:&lt;/p&gt;
&lt;h3 id=&quot;1-global-aliases&quot;&gt;1. Global Aliases&lt;/h3&gt;
&lt;p&gt;To create a global alias, open your Git Bash and use the following command:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;git config --global &lt;span class=&quot;hljs-keyword&quot;&gt;alias&lt;/span&gt;.&lt;span class=&quot;hljs-keyword&quot;&gt;alias&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;_n&lt;/span&gt;ame &lt;span class=&quot;hljs-string&quot;&gt;&#39;original_command&#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Replace &lt;code&gt;alias_name&lt;/code&gt; with your desired alias and &lt;code&gt;original_command&lt;/code&gt; with the Git command you want to abbreviate. For instance, to create an alias for &lt;code&gt;git status&lt;/code&gt;, you would run:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;git config --&lt;span class=&quot;hljs-keyword&quot;&gt;global&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;alias&lt;/span&gt;.st &lt;span class=&quot;hljs-string&quot;&gt;&#39;status&#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;2-local-aliases&quot;&gt;2. Local Aliases&lt;/h3&gt;
&lt;p&gt;Local aliases are specific to a particular repository. Inside the repository&amp;#39;s directory, use the same &lt;code&gt;git config&lt;/code&gt; command without the &lt;code&gt;--global&lt;/code&gt; flag:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;git config &lt;span class=&quot;hljs-keyword&quot;&gt;alias&lt;/span&gt;.&lt;span class=&quot;hljs-keyword&quot;&gt;alias&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;_n&lt;/span&gt;ame &lt;span class=&quot;hljs-string&quot;&gt;&#39;original_command&#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;time-saving-examples&quot;&gt;Time-Saving Examples&lt;/h2&gt;
&lt;p&gt;Now let&amp;#39;s explore some real-world examples of how custom aliases can save a developer&amp;#39;s time:&lt;/p&gt;
&lt;h3 id=&quot;1-abbreviating-common-commands&quot;&gt;1. Abbreviating Common Commands&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;git config --&lt;span class=&quot;hljs-keyword&quot;&gt;global&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;alias&lt;/span&gt;.ci &lt;span class=&quot;hljs-string&quot;&gt;&#39;commit -m&#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With this alias, instead of typing &lt;code&gt;git commit -m &amp;quot;your message&amp;quot;&lt;/code&gt;, you can simply use &lt;code&gt;git ci &amp;quot;your message&amp;quot;&lt;/code&gt;. This minor change might seem inconsequential, but over numerous commits, the saved keystrokes add up.&lt;/p&gt;
&lt;h3 id=&quot;2-complex-workflows&quot;&gt;2. Complex Workflows&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;git config --&lt;span class=&quot;hljs-keyword&quot;&gt;global&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;alias&lt;/span&gt;.feature &lt;span class=&quot;hljs-string&quot;&gt;&#39;checkout -b feature/&#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This alias allows you to create and switch to a new feature branch in one command:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;git &lt;span class=&quot;hljs-built_in&quot;&gt;feature&lt;/span&gt; &lt;span class=&quot;hljs-built_in&quot;&gt;new&lt;/span&gt;-&lt;span class=&quot;hljs-built_in&quot;&gt;feature&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;3-combining-commands&quot;&gt;3. Combining Commands&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;git config --&lt;span class=&quot;hljs-keyword&quot;&gt;global&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;alias&lt;/span&gt;.ac &lt;span class=&quot;hljs-comment&quot;&gt;&#39;!git add -A &amp;amp;&amp;amp; git commit&#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This alias stages all changes and commits them in one step:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;&lt;span class=&quot;hljs-attribute&quot;&gt;git&lt;/span&gt; ac -m &lt;span class=&quot;hljs-string&quot;&gt;&quot;Updated feature&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;4-displaying-a-colorful-log&quot;&gt;4. Displaying a Colorful Log&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;&lt;span class=&quot;hljs-comment&quot;&gt;git&lt;/span&gt; &lt;span class=&quot;hljs-comment&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hljs-literal&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;global&lt;/span&gt; &lt;span class=&quot;hljs-comment&quot;&gt;alias&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;lg&lt;/span&gt; &lt;span class=&quot;hljs-comment&quot;&gt;&#39;log&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hljs-literal&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;graph&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hljs-literal&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;oneline&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hljs-literal&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;all&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hljs-literal&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;decorate&#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, the command &lt;code&gt;git lg&lt;/code&gt; provides a compact, colorful overview of your repository&amp;#39;s history.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Custom aliases in Git Bash are a developer&amp;#39;s secret weapon for improving productivity. By creating shortcuts for frequent commands and complex workflows, you can streamline your version control tasks and save valuable time. Start by identifying the commands you use most often and create aliases to match. With a bit of setup, you&amp;#39;ll be amazed at how much more efficient your Git workflow becomes.&lt;/p&gt;
&lt;p&gt;Remember that while aliases are powerful tools, they should be used judiciously. Overloading your Git Bash environment with too many aliases might make it harder to remember them all. Choose aliases that genuinely enhance your workflow and align with your preferences.&lt;/p&gt;
&lt;p&gt;So, go ahead and unleash the full potential of Git Bash custom aliases. Your fingers will thank you for the reduced typing, and your productivity will soar to new heights!&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/2122990472777291519/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/git-bash-developer-productivity-tips.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/2122990472777291519'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/2122990472777291519'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/git-bash-developer-productivity-tips.html' title='Git Bash Developer Productivity Tips'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-6557554519173608605</id><published>2023-08-23T10:29:00.001+05:30</published><updated>2023-08-23T10:29:14.762+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="architecture"/><category scheme="http://www.blogger.com/atom/ns#" term="CAP"/><category scheme="http://www.blogger.com/atom/ns#" term="CAP theorem"/><category scheme="http://www.blogger.com/atom/ns#" term="concurrency"/><category scheme="http://www.blogger.com/atom/ns#" term="data model"/><category scheme="http://www.blogger.com/atom/ns#" term="database"/><category scheme="http://www.blogger.com/atom/ns#" term="design"/><category scheme="http://www.blogger.com/atom/ns#" term="distributed database"/><category scheme="http://www.blogger.com/atom/ns#" term="fault tolerance"/><category scheme="http://www.blogger.com/atom/ns#" term="key-value"/><category scheme="http://www.blogger.com/atom/ns#" term="nosql"/><category scheme="http://www.blogger.com/atom/ns#" term="replication"/><category scheme="http://www.blogger.com/atom/ns#" term="riak"/><category scheme="http://www.blogger.com/atom/ns#" term="riak database"/><category scheme="http://www.blogger.com/atom/ns#" term="scalability"/><title type='text'>RIAK Database - A Distributed NoSQL Solution</title><content type='html'>&lt;h1 style=&quot;text-align: left&quot;&gt;
  &lt;span 
    &gt;&lt;span 
      &gt;Exploring Riak Database: A Distributed NoSQL Solution&lt;/span
    &gt;&lt;/span
  &gt;
&lt;/h1&gt;
&lt;h3 style=&quot;text-align: left&quot;&gt;
  &lt;span&gt;&lt;span&gt;Introduction&lt;/span&gt;&lt;/span&gt;
&lt;/h3&gt;
&lt;p style=&quot;text-align: left&quot;&gt;
  &lt;span
    &gt;&lt;span
      &gt;In the world of modern technology, data storage and retrieval have become
      crucial aspects of software development. Traditional relational databases
      often struggle to handle the scale and distribution demands of today&#39;s
      applications. This is where Riak, a distributed NoSQL database, comes into
      play. In this article, we will delve into the problem that Riak database
      solves and explore how it addresses these challenges with real-world
      examples.&lt;/span
    &gt;&lt;/span
  &gt;
&lt;/p&gt;
&lt;h2&gt;
  &lt;span&gt;The Problem: Scalability and Fault Tolerance&lt;/span
  &gt;
&lt;/h2&gt;
&lt;p style=&quot;text-align: left&quot;&gt;
  &lt;span &gt;&lt;span
      &gt;Traditional relational databases are built around a fixed schema and a
      single server. As data grows, these databases might struggle to handle the
      load efficiently, leading to performance bottlenecks and scaling
      challenges. Moreover, relying on a single server can be risky – if that
      server fails, data might be lost or unavailable.&lt;/span
    &gt;&lt;/span
  &gt;
&lt;/p&gt;
&lt;h3 style=&quot;text-align: left&quot;&gt;
  &lt;span&gt;Riak&#39;s Solution: Distributed Architecture&lt;/span
  &gt;
&lt;/h3&gt;
&lt;p style=&quot;text-align: left&quot;&gt;
  &lt;span 
    &gt;&lt;span 
      &gt;Riak was designed to tackle these problems head-on. It employs a
      distributed architecture that allows data to be spread across multiple
      nodes or servers. This distribution not only enables horizontal
      scalability – adding more nodes as data grows – but also provides fault
      tolerance. In Riak, data is automatically replicated across nodes,
      ensuring that if one node fails, the data is still accessible from other
      nodes.&lt;/span
    &gt;&lt;/span
  &gt;
&lt;/p&gt;
&lt;h3 style=&quot;text-align: left&quot;&gt;
  &lt;span
    &gt;Data Model: Key-Value Store&lt;/span
  &gt;
&lt;/h3&gt;
  &lt;span 
    &gt;&lt;span
      &gt;Riak follows a key-value store data model. Each piece of data is
      associated with a unique key, and data retrieval is performed using these
      keys. This model simplifies data storage and retrieval and is well-suited
      for scenarios where flexible schema design is required.&lt;/span
    &gt;&lt;/span
  &gt;
&lt;h3 style=&quot;text-align: left&quot;&gt;
  &lt;span
    &gt;Sample Scenario: E-Commerce Application&lt;/span
  &gt;
&lt;/h3&gt;
  &lt;span 
    &gt;&lt;span 
      &gt;Imagine an e-commerce application using Riak to handle product
      information. Each product is identified by a unique product ID, which
      serves as the key. The product details, such as name, price, and
      description, are stored as values. Riak&#39;s distributed nature ensures that
      even during high traffic or server failures, the product information
      remains available and accessible.&lt;/span
    &gt;&lt;/span
  &gt;
&lt;h3 style=&quot;text-align: left&quot;&gt;
  &lt;span
    &gt;CAP Theorem and Riak&lt;/span
  &gt;
&lt;/h3&gt;
  &lt;span 
    &gt;&lt;span 
      &gt;The CAP theorem states that in a distributed system, it&#39;s challenging to
      achieve Consistency, Availability, and Partition tolerance simultaneously.
      Riak follows the AP (Availability and Partition tolerance) model. It
      ensures that even in the face of network partitions, the system remains
      available, sacrificing strong consistency.&lt;/span
    &gt;&lt;/span
  &gt;
&lt;h3 style=&quot;text-align: left&quot;&gt;
  &lt;span
    &gt;Concurrency Control: Vector Clocks&lt;/span
  &gt;
&lt;/h3&gt;
&lt;p style=&quot;text-align: left&quot;&gt;
  &lt;span 
    &gt;&lt;span 
      &gt;Riak employs vector clocks to manage concurrent updates to the same piece
      of data across nodes. These clocks help determine the causal ordering of
      events, enabling Riak to resolve conflicts and reconcile multiple versions
      of the data.&lt;/span
    &gt;&lt;/span
  &gt;
&lt;/p&gt;
&lt;h3 style=&quot;text-align: left&quot;&gt;
  &lt;span
    &gt;Use Cases&lt;/span
  &gt;
&lt;/h3&gt;
&lt;p style=&quot;text-align: left&quot;&gt;
  &lt;span 
    &gt;&lt;span 
      &gt;Riak is particularly well-suited for scenarios where high availability
      and fault tolerance are critical. It&#39;s often used in applications like
      real-time analytics, content delivery, and session management.&lt;/span
    &gt;&lt;/span
  &gt;
&lt;/p&gt;
&lt;h3 style=&quot;text-align: left&quot;&gt;
  &lt;span
    &gt;Conclusion&lt;/span
  &gt;
&lt;/h3&gt;
&lt;p style=&quot;text-align: left&quot;&gt;
  &lt;span 
    &gt;&lt;span 
      &gt;Riak database addresses the challenges of scalability and fault tolerance
      that traditional relational databases face. Its distributed architecture,
      key-value data model, and use of vector clocks for concurrency control
      make it a powerful solution for applications requiring high availability
      and flexible data storage. By embracing Riak&#39;s design principles,
      developers can build robust, resilient, and scalable systems that meet the
      demands of modern technology.&lt;/span
    &gt;&lt;/span
  &gt;
&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/6557554519173608605/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/riak-database-distributed-nosql-solution.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/6557554519173608605'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/6557554519173608605'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/riak-database-distributed-nosql-solution.html' title='RIAK Database - A Distributed NoSQL Solution'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-4069642728729316963</id><published>2023-08-20T17:28:00.003+05:30</published><updated>2023-08-20T17:28:53.699+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="multi-tenancy"/><category scheme="http://www.blogger.com/atom/ns#" term="multi-tenant"/><category scheme="http://www.blogger.com/atom/ns#" term="spring"/><category scheme="http://www.blogger.com/atom/ns#" term="spring boot"/><category scheme="http://www.blogger.com/atom/ns#" term="spring cloud config server"/><title type='text'>Using Spring Cloud Config Server for Multi-tenancy configuration</title><content type='html'>Let&#39;s walk through a basic example of how to set up and use Spring Cloud Config
Server to manage configuration for multiple tenants in a Spring Boot
Application.

&lt;h5&gt;Step 1: Create a Spring Cloud Config Server&lt;/h5&gt;

Create a new Spring Boot project with the Spring Cloud Config Server dependency.

&lt;pre&gt;
&amp;lt;!-- pom.xml --&amp;gt;
&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;org.springframework.cloud&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;spring-cloud-config-server&amp;lt;/artifactId&amp;gt;
&amp;lt;/dependency&amp;gt;
&lt;/pre&gt;
Configure the Spring Cloud Config Server:
&lt;pre&gt;
// src/main/java/com/example/ConfigServerApplication.java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;

@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }
}
&lt;/pre&gt;

Configure the application properties to specify the Git repository where
configuration files are stored:
&lt;pre&gt;
# src/main/resources/application.yml
spring:
  cloud:
    config:
      server:
        git:
          uri: &amp;lt;URL to your Git repository&amp;gt;
&lt;/pre&gt;
&lt;h5&gt;Step 2: Create Configuration Files for Tenants&lt;/h5&gt;
In your Git repository, organize configuration files based on tenants and
profiles:
&lt;pre&gt;
 config-repo/
|-- application-tenant1.properties
|-- application-tenant2.properties
|-- application.yml
&lt;/pre&gt;

&lt;div&gt;
  Example content for application-tenant1.properties:
  &lt;pre&gt;
# application-tenant1.properties
greeting.message=Hello from Tenant 1!
&lt;/pre
  &gt;
&lt;/div&gt;
&lt;div&gt;
  Example content for application-tenant2.properties:
  &lt;pre&gt;
# application-tenant2.properties
greeting.message=Hello from Tenant 2!
&lt;/pre
  &gt;
&lt;/div&gt;

&lt;h5&gt;Step 3: Create a Spring Boot Application&lt;/h5&gt;

Create a new Spring Boot project for the multi-tenant application:
&lt;pre&gt;

&amp;lt;dependencies&amp;gt;
  &amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;spring-boot-starter-web&amp;lt;/artifactId&amp;gt;
  &amp;lt;/dependency&amp;gt;
  &amp;lt;!-- Other dependencies --&amp;gt;
&amp;lt;/dependencies&amp;gt;

&lt;/pre&gt;
Configure the application to use the Spring Cloud Config Client:
&lt;pre&gt;
# src/main/resources/bootstrap.yml 
spring:
  application:
    name: myapp
  cloud:
    config:
      uri: http://localhost:8888 # URL to your Config Server
&lt;/pre&gt;

Create a controller to retrieve the configuration property:
&lt;pre&gt;
// src/main/java/com/example/MyAppController.java
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MyAppController {
    @Value(&quot;${greeting.message}&quot;)
    private String greetingMessage;

    @GetMapping(&quot;/greeting&quot;)
    public String getGreetingMessage() {
        return greetingMessage;
    }
}
&lt;/pre&gt;
&lt;h5&gt;Step 4: Test the Application&lt;/h5&gt;
&lt;ol&gt;
  &lt;li&gt;Start the Spring Cloud Config Server application.&lt;/li&gt;
  &lt;li&gt;Start the multi-tenant Spring Boot application.&lt;/li&gt;
  &lt;li&gt;
    Access the greeting message for each tenant using the /greeting endpoint:
    &lt;ol&gt;
      &lt;li&gt;For Tenant 1: http://localhost:8080/greeting&lt;/li&gt;
      &lt;li&gt;For Tenant 2: http://localhost:8080/greeting&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ol&gt;

The Spring Cloud Config Server will provide the appropriate configuration
properties based on the tenant-specific profile used in the application. This
example demonstrates a basic setup of using Spring Cloud Config Server to manage
configuration for multiple tenants in a Spring Boot application.

&lt;div&gt;
  &lt;h4&gt;Dynamic Tenant identification - Simple approach&lt;/h4&gt;
  &lt;div&gt;
    To dynamically load the configuration for different tenants based on a URL
    parameter or path segment, you can use Spring Cloud Config&#39;s native support
    for profiles and the application name to achieve this. Here&#39;s how you can
    modify the configuration to achieve dynamic loading of tenant-specific
    configurations:
  &lt;/div&gt;
  &lt;div&gt;
    &lt;p&gt;
      Below given is a sample yaml configuration that can be used to dynamically
      identify the tenant
    &lt;/p&gt;
    &lt;pre&gt;
# src/main/resources/bootstrap.yml
spring:
  cloud:
    config:
      uri: http://localhost:8888
  application:
    name: myapp # The base application name
  profiles:
    active: @tenant # Placeholder for the active profile

    &lt;/pre&gt;
  &lt;/div&gt;
  &lt;h4&gt;Tenant Identification from URL&lt;/h4&gt;
  &lt;pre&gt;
// src/main/java/com/example/MyAppController.java
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MyAppController {
    @Value(&quot;${greeting.message}&quot;)
    private String greetingMessage;

    @GetMapping(&quot;/greeting/{tenant}&quot;)
    public String getGreetingMessage(@PathVariable String tenant) {
        // Set the active profile dynamically based on the tenant
        System.setProperty(&quot;spring.profiles.active&quot;, tenant);
        try {
            // Business logic using the tenant-specific profile
            return greetingMessage;
        } finally {
            // Clean up the active profile to avoid affecting subsequent requests
            System.clearProperty(&quot;spring.profiles.active&quot;);
        }
    }
}
  &lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
  &lt;h4&gt;Access Configuration via URL Path:&lt;/h4&gt;
  &lt;div&gt;
    Now you can access the tenant-specific configuration by specifying the
    tenant as a path segment in the URL. For example:
    &lt;ol&gt;
      &lt;li&gt;For Tenant 1: http://localhost:8080/greeting/tenant1&lt;/li&gt;
      &lt;li&gt;For Tenant 2: http://localhost:8080/greeting/tenant2&lt;/li&gt;
    &lt;/ol&gt;
    Each URL will dynamically set the active profile based on the tenant, and
    the Spring Cloud Config Server will serve the corresponding tenant-specific
    configuration properties.
  &lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/4069642728729316963/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/using-spring-cloud-config-server-for.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/4069642728729316963'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/4069642728729316963'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/using-spring-cloud-config-server-for.html' title='Using Spring Cloud Config Server for Multi-tenancy configuration'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-7046523397774410360</id><published>2023-08-20T16:19:00.002+05:30</published><updated>2023-08-20T16:30:05.183+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="apache"/><category scheme="http://www.blogger.com/atom/ns#" term="avro"/><category scheme="http://www.blogger.com/atom/ns#" term="data encoding"/><category scheme="http://www.blogger.com/atom/ns#" term="data format"/><category scheme="http://www.blogger.com/atom/ns#" term="deserialization"/><category scheme="http://www.blogger.com/atom/ns#" term="encoding"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="Serialization"/><title type='text'>Using Apache Avro for Efficient Data Serialization</title><content type='html'>&lt;div&gt;
&lt;h3&gt;Introduction&lt;/h3&gt;
&lt;div&gt;In the world of software development, efficient data serialization plays a crucial role in enabling smooth communication between different components, systems, and applications. One popular technology that addresses the challenges of data serialization is Apache Avro. Avro is a powerful and versatile framework that offers a compact and efficient way to serialize data, making it an ideal choice for various scenarios. In this article, we will explore the need for efficient data serialization, the problems it helps us solve, and how to use Apache Avro with Java, using a &quot;Product&quot; entity as an example. &lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;The Need for Efficient Data Serialization&lt;/h3&gt;
&lt;div&gt;
  Modern software systems are often composed of multiple components running on different platforms and communicating over various protocols. This communication involves sending data between these components, which can be in different formats and structures. Data serialization is the process of converting complex data structures, such as objects, into a format that can be easily transmitted and reconstructed on the receiving end.&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;Efficient data serialization is crucial for several reasons:&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;
Reduced Bandwidth Usage: &lt;/strong&gt;Efficient serialization techniques minimize the amount of data that needs to be transmitted over the network, reducing bandwidth consumption and resulting in faster communication.
    &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;
Optimized Storage:&lt;/strong&gt; Compact serialized data requires less storage space, which is particularly important when dealing with large volumes of data. &lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;
Interoperability: &lt;/strong&gt;Different programming languages and platforms might have different native data representations. A standardized serialization format ensures that data can be easily exchanged between systems regardless of the underlying technology.&lt;/li&gt;
        &lt;li&gt;&lt;strong&gt;
          Versioning: &lt;/strong&gt; As software systems evolve, data structures may change. A well-designed serialization format should support backward and forward compatibility to avoid breaking existing systems when changes occur. 
        &lt;/li&gt;
&lt;/ol&gt; 
          &lt;/div&gt;
  &lt;hr /&gt;
  &lt;div&gt;
  &lt;h3&gt;Problems Solved by Apache Avro&lt;/h3&gt;
&lt;div&gt;Apache Avro addresses several problems associated with data serialization:&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Schema Evolution:&lt;/strong&gt; Avro uses a schema-based approach to serialization, where the schema is included with the data. This enables seamless evolution of data structures over time without requiring modifications to the consumer code. Old and new versions of schemas can coexist, allowing data compatibility between different versions of an application.
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Compact Binary Format: &lt;/strong&gt;Avro&#39;s binary encoding is highly compact, resulting in reduced network traffic and storage requirements. This is particularly beneficial for applications dealing with large datasets.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dynamic Typing: &lt;/strong&gt;Avro allows dynamic typing, which means that data types are defined in the schema itself. This provides flexibility and makes it easier to work with data from different sources.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Code Generation:&lt;/strong&gt; Avro provides code generation capabilities, allowing you to generate Java classes from Avro schemas. This reduces the effort required to serialize and deserialize data while also enhancing type safety.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
  &lt;strong&gt;Using Apache Avro with Java: The &quot;Product&quot; Entity Example&lt;/strong&gt;
&lt;/div&gt;
&lt;div&gt;
  Let&#39;s explore how to use Apache Avro with a simple &quot;Product&quot; entity in Java.
  We will define an Avro schema for the &quot;Product&quot; entity, generate Java classes
  from the schema, and demonstrate serialization and deserialization.
&lt;/div&gt;
&lt;div&gt;
  &lt;h3&gt;Step 1: Define the Avro Schema&lt;/h3&gt;
  &lt;pre&gt;
{
  &quot;type&quot;: &quot;record&quot;,
  &quot;name&quot;: &quot;Product&quot;,
  &quot;fields&quot;: [
    {&quot;name&quot;: &quot;id&quot;, &quot;type&quot;: &quot;int&quot;},
    {&quot;name&quot;: &quot;name&quot;, &quot;type&quot;: &quot;string&quot;},
    {&quot;name&quot;: &quot;price&quot;, &quot;type&quot;: &quot;double&quot;}
  ]
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
    &lt;h3&gt;Step 2: Generate Java Classes&lt;/h3&gt;
    &lt;p&gt;Use the Avro tool to generate Java classes from the schema:&lt;/p&gt;
    &lt;pre&gt;$ java -jar avro-tools-1.10.2.jar compile schema product.avsc ./output&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;
    &lt;h3&gt;Step 3: Serialization and Deserialization&lt;/h3&gt;
    &lt;p&gt;The sample code given below demonstrate the serialization and deserialization&lt;/p&gt;
    &lt;pre&gt;import org.apache.avro.file.DataFileReader;
import org.apache.avro.file.DataFileWriter;
import org.apache.avro.io.DatumReader;
import org.apache.avro.io.DatumWriter;
import org.apache.avro.specific.*;
import java.io.File;
import java.io.IOException;

public class AvroExample {

    public static void main(String[] args) throws IOException {
        Product product = new Product();
        product.setId(1);
        product.setName(&quot;Sample Product&quot;);
        product.setPrice(29.99);

        // Serialize the object to a file
        DatumWriter&amp;lt;Product&amp;gt; productDatumWriter = new SpecificDatumWriter&amp;lt;&amp;gt;(Product.class);
        DataFileWriter&amp;lt;Product&amp;gt; dataFileWriter = new DataFileWriter&amp;lt;&amp;gt;(productDatumWriter);
        dataFileWriter.create(product.getSchema(), new File(&quot;product.avro&quot;));
        dataFileWriter.append(product);
        dataFileWriter.close();

        // Deserialize the object from the file
        DatumReader&amp;lt;Product&amp;gt; productDatumReader = new SpecificDatumReader&amp;lt;&amp;gt;(Product.class);
        DataFileReader&amp;lt;Product&amp;gt; dataFileReader = new DataFileReader&amp;lt;&amp;gt;(new File(&quot;product.avro&quot;), productDatumReader);
        Product deserializedProduct = dataFileReader.next();
        dataFileReader.close();

        System.out.println(&quot;Deserialized Product: &quot; + deserializedProduct);
    }
}
&lt;/pre&gt;
&lt;div&gt;In this example, we define an Avro schema for the &quot;Product&quot; entity, generate Java classes using the Avro tool, and then demonstrate serialization and deserialization using these classes.&lt;/div&gt;
&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
    &lt;h3&gt;Conclusion&lt;/h3&gt;
    &lt;div&gt;
        Efficient data serialization is a critical aspect of modern software development, enabling smooth communication between different components and systems. Apache Avro addresses the challenges of data serialization by providing a schema-based, compact, and efficient approach. With its support for schema evolution, code generation, and dynamic typing, Avro is an excellent choice for various serialization scenarios. By following the steps outlined in this article and using the provided Java example, you can integrate Apache Avro into your projects to achieve efficient data serialization and transmission.
    &lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/7046523397774410360/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/using-apache-avro-for-efficient-data.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/7046523397774410360'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/7046523397774410360'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2023/08/using-apache-avro-for-efficient-data.html' title='Using Apache Avro for Efficient Data Serialization'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-5763376925275299363</id><published>2022-08-08T13:13:00.000+05:30</published><updated>2022-08-08T13:13:00.705+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="next"/><category scheme="http://www.blogger.com/atom/ns#" term="next.js"/><category scheme="http://www.blogger.com/atom/ns#" term="pages"/><category scheme="http://www.blogger.com/atom/ns#" term="pages in next.js"/><title type='text'>pages in next.js</title><content type='html'>&lt;h1&gt;Introduction&lt;/h1&gt;&lt;div&gt;Next.js contains a feature called as Pages that helps us to maintain a clear isolation of the page level components and their layouts.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This helps us in having page and routing implementations separate from the components, helping in isolation of the application layout / presentation with that of the functional components&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This segregation helps us in having slim components and isolate the layout / page level actions. Also, since there are pages, the components that comprise a page atleast at the higher level can be easily found out in this system.&lt;/div&gt;
&lt;div&gt;
  
&lt;/div&gt;

&lt;h1&gt;Problem Statement&lt;/h1&gt;&lt;div&gt;&lt;div&gt;We have been using react.js for building SPA (Single Page Applications) for a while and we experienced that some features like pages and routing are not very comfortable with react.js&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Compared with other frameworks, react does not have option to fully perform the routing and having pages. There are times where we have to duplicate the layouts to all components that act like pages in the react application.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;These are resulting in lots of code getting redundant and duplicated across various components in react.js application.&lt;/div&gt;&lt;/div&gt;
&lt;div&gt;
  
&lt;/div&gt;
&lt;h1&gt;Solution&lt;/h1&gt;&lt;div&gt;Pages are configured in a Next.js application and the directory structure looks like the one below&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Application Root&lt;/div&gt;&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;gt; components&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;gt; pages&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;gt; aboutus&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;gt; contact&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;gt; products&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;gt; index.js (this normally is the entry point file in the page, this typically will invoke the list of products through its component)&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;gt; [productId].js (this filename contains the route parameter as a placeholder in the filename itself thereby visually expressing that this file needs a URL Query parameter. In our example, this productId is the id of the product and this page will have components that will render the details of a product.)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;This file system organization helps us in the following,&lt;/div&gt;&lt;div&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;1. Clear separation of what goes in a page&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;2. Visual indication in the file name itself of what a file is responsible for and also what the parameters the component requires&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;3. The pages are also react.js components, so that there is no extra effort to learn / implement the pages features&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I will share sample application on features of Next.js in subsequent blog posts.&lt;/div&gt;
&lt;div&gt;
  
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/5763376925275299363/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2022/08/pages-in-nextjs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/5763376925275299363'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/5763376925275299363'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2022/08/pages-in-nextjs.html' title='pages in next.js'/><author><name>saravanan</name><uri>http://www.blogger.com/profile/08466191670706652471</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-3458813097549737812</id><published>2022-06-17T13:15:00.003+05:30</published><updated>2022-06-17T13:16:07.425+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="clone table data"/><category scheme="http://www.blogger.com/atom/ns#" term="clone table schema"/><category scheme="http://www.blogger.com/atom/ns#" term="data migration"/><category scheme="http://www.blogger.com/atom/ns#" term="database"/><category scheme="http://www.blogger.com/atom/ns#" term="mysql"/><category scheme="http://www.blogger.com/atom/ns#" term="schema change and migration"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="sql query"/><title type='text'>How to make table schema changes and restore data after appropriate transformation</title><content type='html'>&lt;meta content=&quot;mysql,schema change and migration,data migration,database,SQL,sql query,clone table schema,clone table data&quot; name=&quot;keywords&quot; /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;Introduction&lt;/h2&gt;&lt;p style=&quot;text-align: left;&quot;&gt;In many cases we might have to encounter scenarios where we need to perform backup of data or perform a schema change like data type transformation etc.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;This blog post illustrates the steps that can be used as a checklist to perform the operation at ease&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Steps&lt;/h2&gt;&lt;div&gt;The below sql query creates a new table with the same schema as given in the like field&lt;/div&gt;&lt;div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;create&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;table&lt;/span&gt; &amp;lt;table_name&amp;gt;_old &lt;span style=&quot;color: #569cd6;&quot;&gt;like&lt;/span&gt; &amp;lt;table_name&amp;gt;;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;Now that we have the schema ready, we can copy the data for backup using the below command&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;insert&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;into&lt;/span&gt; &amp;lt;table_name&amp;gt;_old &lt;span style=&quot;color: #569cd6;&quot;&gt;select&lt;/span&gt; * &lt;span style=&quot;color: #569cd6;&quot;&gt;from&lt;/span&gt; &amp;lt;table_name&amp;gt;;&lt;/div&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;Once the above command succeeds, we can drop the old table&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;drop&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;table&lt;/span&gt; &amp;lt;table_name&amp;gt;;&lt;/div&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;Then we can create the new table with the same name as the one given in &lt;i&gt;&lt;b&gt;&amp;lt;table_name&amp;gt;&lt;/b&gt;&amp;nbsp;&lt;/i&gt;so that we can allow applications to still use the same table name.&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;CREATE&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;TABLE&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;`&amp;lt;table_name&amp;gt;`&lt;/span&gt; (&lt;/div&gt;&lt;div&gt;&amp;nbsp; &lt;span style=&quot;color: #ce9178;&quot;&gt;`id`&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;bigint&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;NOT&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;NULL&lt;/span&gt; AUTO_INCREMENT,&lt;/div&gt;&lt;div&gt;...);&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;Now that the table with new schema is ready, we can migrate the data from the old table to the new table using below like query&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;insert&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;into&lt;/span&gt; &amp;lt;table_name&amp;gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;select&lt;/span&gt; * &lt;span style=&quot;color: #569cd6;&quot;&gt;from&lt;/span&gt; &amp;lt;table_name&amp;gt;_old;&lt;/div&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;Here, we are using a simple &lt;i style=&quot;font-weight: bold;&quot;&gt;select * from&amp;nbsp;&lt;/i&gt;&amp;nbsp;query, but in real time there might be joins or other ways to arrive at the transformed data.&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;This way we can ensure that the table data is transformed to the new schema and is ready to be used.&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;Verify the newly migrated data using a select query like given below&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;select&lt;/span&gt; * &lt;span style=&quot;color: #569cd6;&quot;&gt;from&lt;/span&gt; &amp;lt;table_name&amp;gt;;&lt;/div&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;Once all the records are looking good, we can drop the old table as it might be occupying lot of memory due to the redundant data, which can be done using the below command.&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #569cd6;&quot;&gt;drop&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;table&lt;/span&gt; &amp;lt;table_name&amp;gt;_old;&lt;/div&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;Hope this helps :)&amp;nbsp;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/3458813097549737812/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2022/06/how-to-make-table-schema-changes-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/3458813097549737812'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/3458813097549737812'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2022/06/how-to-make-table-schema-changes-and.html' title='How to make table schema changes and restore data after appropriate transformation'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-2029034823599916818</id><published>2022-06-16T16:25:00.002+05:30</published><updated>2022-06-16T16:26:08.298+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="backup"/><category scheme="http://www.blogger.com/atom/ns#" term="backup table data as sql"/><category scheme="http://www.blogger.com/atom/ns#" term="batch script"/><category scheme="http://www.blogger.com/atom/ns#" term="database"/><category scheme="http://www.blogger.com/atom/ns#" term="filtered data in backup"/><category scheme="http://www.blogger.com/atom/ns#" term="mysql"/><category scheme="http://www.blogger.com/atom/ns#" term="mysqldump"/><category scheme="http://www.blogger.com/atom/ns#" term="mysqldump.exe"/><category scheme="http://www.blogger.com/atom/ns#" term="sql script"/><category scheme="http://www.blogger.com/atom/ns#" term="windows"/><title type='text'>using mysqldump command to backup the data from MySQL Database table</title><content type='html'>&lt;meta content=&quot;mysql,mysqldump,mysqldump.exe,windows,batch script,backup,sql script,filtered data in backup,database,backup table data as sql&quot; name=&quot;keywords&quot; /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;Introduction&lt;/h2&gt;&lt;div&gt;In this blog post, we will take a look at the &lt;b&gt;&lt;i&gt;mysqldump &lt;/i&gt;&lt;/b&gt;command that is shipped as part of the MySQL clients.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Data Backup&lt;/h2&gt;&lt;div&gt;We normally deal with backup of data by exporting the data as JSON / CSV or as SQL Files. This is required so that any change that we are working on might have a impact, we can immediately use the backup to fix any unexpected database operation.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;When working with JSON / CSV at times, we have to deal with the issues in the data formats. Further as SQL queries, we get the option to rewrite the query, insert them into a local database, perform the required transform or operations and then move to the server.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The MySQL Workbench provides the export option through which we can generate the SQL scripts, but there are issues like the target table names are empty and there is a new insert statement for each row in the table.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Example Command&lt;/h3&gt;&lt;div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;div&gt;mysqldump.exe &lt;/div&gt;&lt;div&gt;--host=servername --port=&lt;span style=&quot;color: #b5cea8;&quot;&gt;3306&lt;/span&gt; --default-character-set=utf8 &lt;/div&gt;&lt;div&gt;--user=(db_user_name) -p --protocol=tcp --column-statistics=FALSE --skip-triggers&lt;/div&gt;&lt;div&gt;--set-gtid-purged=OFF --no-create-info --quick --max_allowed_packet=512M --skip-lock-tables &lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;db_name&quot;&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;table_name&quot;&lt;/span&gt; --where=&lt;span style=&quot;color: #ce9178;&quot;&gt;&quot;column_name=&#39;value&#39;&quot;&lt;/span&gt; &amp;gt; script_name.sql&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;As we can see in the above command, we have provided the following arguments&lt;/div&gt;&lt;div&gt;--host -&amp;gt; to provide the server name&amp;nbsp;&lt;/div&gt;&lt;div&gt;--user -&amp;gt; the database connectivity user name&lt;/div&gt;&lt;div&gt;--port -&amp;gt; default to 3306 or custom port if used&lt;/div&gt;&lt;div&gt;--default-character -&amp;gt; we are using utf8, it can be based on the char set defined in the table schema&lt;/div&gt;&lt;div&gt;-p -&amp;gt; to prompt for the server password&lt;/div&gt;&lt;div&gt;--protocol -&amp;gt; by default, we are using the tcp protocol&lt;/div&gt;&lt;div&gt;--skip-triggers -&amp;gt; to skip invocation of triggers&amp;nbsp;&lt;/div&gt;&lt;div&gt;--set-git-purged -&amp;gt; to skip the global transaction identifiers&lt;/div&gt;&lt;div&gt;--no-create -&amp;gt; to not include the create table script as part of the generated sql files&lt;/div&gt;&lt;div&gt;--quick -&amp;gt; for handling large volume of data&lt;/div&gt;&lt;div&gt;--max_allowed_packet -&amp;gt; to set a max packet size, we are using 512 MB&lt;/div&gt;&lt;div&gt;--skip-lock-tables -&amp;gt; to avoid locking table during running the query, default is to lock the table&lt;/div&gt;&lt;div&gt;--where -&amp;gt; adds a filter condition to the generated query so that, we can split into chunks or focus on the required subset of data in the export&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I have tried this and it works fine. Hope this helps for anyone in need.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/2029034823599916818/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2022/06/using-mysqldump-command-to-backup-data.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/2029034823599916818'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/2029034823599916818'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2022/06/using-mysqldump-command-to-backup-data.html' title='using mysqldump command to backup the data from MySQL Database table'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-1297481886386915050</id><published>2022-06-15T17:14:00.004+05:30</published><updated>2022-06-15T17:15:39.159+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="chrome"/><category scheme="http://www.blogger.com/atom/ns#" term="firefox"/><category scheme="http://www.blogger.com/atom/ns#" term="http"/><category scheme="http://www.blogger.com/atom/ns#" term="http/2"/><category scheme="http://www.blogger.com/atom/ns#" term="http/3"/><category scheme="http://www.blogger.com/atom/ns#" term="http2"/><category scheme="http://www.blogger.com/atom/ns#" term="http3"/><category scheme="http://www.blogger.com/atom/ns#" term="litespeed"/><category scheme="http://www.blogger.com/atom/ns#" term="quic"/><category scheme="http://www.blogger.com/atom/ns#" term="ssl"/><category scheme="http://www.blogger.com/atom/ns#" term="TCP"/><category scheme="http://www.blogger.com/atom/ns#" term="TLS"/><category scheme="http://www.blogger.com/atom/ns#" term="TLS1.2"/><category scheme="http://www.blogger.com/atom/ns#" term="TLS1.3"/><category scheme="http://www.blogger.com/atom/ns#" term="UDP"/><title type='text'>http/3</title><content type='html'>&lt;meta content=&quot;http3,http,http/3,http2,http/2,quic,chrome,firefox,TCP,UDP,litespeed,ssl,TLS,TLS1.2,TLS1.3&quot; name=&quot;keywords&quot; /&gt;
&lt;h1 style=&quot;text-align: left;&quot;&gt;Introduction&lt;/h1&gt;&lt;div&gt;HTTP/3 is the 3rd major version of the HTTP protocol that powers the internet. In comparison with the previous version of http which relied on TCP, http/3 relies on QUIC.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;QUIC&lt;/h2&gt;&lt;div&gt;Specification published at 6th June, 2022&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Developed initially at Google in 2012, had its way to IETF and public by 2022. A decade for completion and standardization !!!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Are the semantics like requests, methods, status codes still the same like previous versions of http/2?&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;yes, they still remain the same&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The underlying mechanisms are changed, like http/3 uses space congestion control over UDP (User Datagram protocol)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Head-Of-Line Blocking (HOL)&lt;/h3&gt;&lt;div&gt;This is a performance problem where there is a queue of packets built due to the first packet that is yet to be consumed.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We have browsers that have limits on the number of parallel requests that it can send to a server, when they are used up, as we anticipate, a Queue is formed for the newer requests that start accumulating the newer requests till the former requests are completely processed.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We had HTTP/2 to address this issue by the process of multiplexing which eliminates this HOL at the application layer. However there is still a blocking HOL in the TCP layer.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This was a bottleneck that limits the performance. Hence, QUIC solves this problem by using multiplexing with UDP and thereby removing the HOL with TCP.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So, we get to leverage good performance.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;0-RTT&lt;/h3&gt;&lt;div&gt;For any server and client that have been connected in the past, there is no formal introduction - acknowledgements. More like we talking to our friends without any formal introduction / waiting for they to acknowledge our greetings etc, so we make requests responded quick through (QUIC)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Encryption by Default&lt;/h3&gt;&lt;div&gt;The data at the application layer will always be encrypted. There is no separate TCP handshake and TLS handshake which were distinct events in the previous versions of HTTP.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;In this case how are the encryptions and connections managed?&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;QUIC sets up the encrypted connections at the transport layer. Since this is happening as a single action, applications does not need to perform a TCP handshake and a TLS handshake.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Further, packet number and few other headers are encrypted by default giving a tough time for the hackers to understand what is going on.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Are there apps out in http/3?&amp;nbsp;&lt;/h3&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;yes,&amp;nbsp;&lt;/i&gt;&lt;/b&gt;I have seen apps from Google, cloudflare using http3 for many of their apps. The below is the network capture in Google Chrome new tab which loads content from google&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjS70WYBRdtkRBxW48j5V9VMS1JiLQ-Vb4FHy_ip6kk1cPH1fyqJadPnsl9ZN4l9_bzUS2s9-F6KNA_hXrTTFLCFp2W-Nj8J8-n5lOEFYRJzKmu4ilU_iwCpsEGHA21GCWvDvUtbFg1OfEdwJmiPFMwYsubxpgTAyKf3cU8lnT9MUzZ0z-6vNVIa42jGA&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;203&quot; data-original-width=&quot;1899&quot; height=&quot;69&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjS70WYBRdtkRBxW48j5V9VMS1JiLQ-Vb4FHy_ip6kk1cPH1fyqJadPnsl9ZN4l9_bzUS2s9-F6KNA_hXrTTFLCFp2W-Nj8J8-n5lOEFYRJzKmu4ilU_iwCpsEGHA21GCWvDvUtbFg1OfEdwJmiPFMwYsubxpgTAyKf3cU8lnT9MUzZ0z-6vNVIa42jGA=w640-h69&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Browser Support&lt;/h3&gt;&lt;/div&gt;&lt;div&gt;Most of the leading browsers support HTTP/3. Chrome (79 and onwards), Firefox (72 and onwards) etc&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Web Server Support&lt;/h3&gt;&lt;div&gt;Currently, the LiteSpeed Webserver supports HTTP/3. I did try it out for a Java App and realized that it was not easy as there were listeners and the team was not sure on the use of them. I feel that running an app on another webserver while using Litespeed as a proxy can be used to achieve support for HTTP/3.&lt;/div&gt;&lt;div&gt;I will try it out in the upcoming days and share my findings or steps for the same.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;However, Kestrel, Nginx webservers do seem to have a good support for the HTTP/3. Also, IIS in Windows Server 2022 has support, looks like some registry keys are to be setup to enable HTTP3&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We have just scratched the surface and as we delve into the details, things will get very interesting.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/1297481886386915050/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2022/06/http3.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/1297481886386915050'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/1297481886386915050'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2022/06/http3.html' title='http/3'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEjS70WYBRdtkRBxW48j5V9VMS1JiLQ-Vb4FHy_ip6kk1cPH1fyqJadPnsl9ZN4l9_bzUS2s9-F6KNA_hXrTTFLCFp2W-Nj8J8-n5lOEFYRJzKmu4ilU_iwCpsEGHA21GCWvDvUtbFg1OfEdwJmiPFMwYsubxpgTAyKf3cU8lnT9MUzZ0z-6vNVIa42jGA=s72-w640-h69-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-2338930528948349273</id><published>2022-06-13T13:36:00.000+05:30</published><updated>2022-06-13T13:36:00.435+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="chunks"/><category scheme="http://www.blogger.com/atom/ns#" term="command line"/><category scheme="http://www.blogger.com/atom/ns#" term="commands"/><category scheme="http://www.blogger.com/atom/ns#" term="GB"/><category scheme="http://www.blogger.com/atom/ns#" term="git"/><category scheme="http://www.blogger.com/atom/ns#" term="git bash"/><category scheme="http://www.blogger.com/atom/ns#" term="large files"/><category scheme="http://www.blogger.com/atom/ns#" term="mb"/><category scheme="http://www.blogger.com/atom/ns#" term="partition"/><category scheme="http://www.blogger.com/atom/ns#" term="split"/><category scheme="http://www.blogger.com/atom/ns#" term="terminal"/><title type='text'>Split a very large file in to chunks </title><content type='html'>&lt;meta content=&quot;git, large files, git bash, split, GB, mb, split, chunks, partition, command line, terminal, commands&quot; name=&quot;keywords&quot;&gt;&lt;/meta&gt;&lt;h1 style=&quot;text-align: left;&quot;&gt;
Introduction&lt;/h1&gt;&lt;div&gt;Many a times we are having to deal with the very large files, be it the logs from the server like &lt;b&gt;catalina.out&amp;nbsp;&lt;/b&gt;&lt;i&gt;&amp;nbsp;&lt;/i&gt;or any other huge sql files or csv or text files.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;These are some artifacts that could have been generated in the server or might contain the data. There might not have been detailed logging systems that can do a &lt;i style=&quot;font-weight: bold;&quot;&gt;RollingFile &lt;/i&gt;like appender that can get the files into smaller chunks for us to use easily. In some cases these could be large data which is hard to split into multiple chunks in an export mechanism.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Problem Statement&lt;/h2&gt;&lt;div&gt;When we try to open them in an editor like&amp;nbsp;&lt;i style=&quot;font-weight: bold;&quot;&gt;Notepad / Notepad++ / VS Code&lt;/i&gt;, we normally run into memory issues and the application gets frozen.&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;At times, in case of windows, we might have to go to&amp;nbsp;&lt;i style=&quot;font-weight: bold;&quot;&gt;Task Manager&amp;nbsp;&lt;/i&gt;, find the application and then&amp;nbsp;&lt;i style=&quot;font-weight: bold;&quot;&gt;End Task&amp;nbsp;&lt;/i&gt;so that we can use the other apps or to allow that particular application to be usage&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Solution&lt;/h2&gt;&lt;div&gt;In this post, we explore on using git bash a tool. We normally use a git bash command line interface that can be used to perform the git operations. In this case we can use a useful command in git bash that can help us here. Open git bash from the windows or linux system.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Assuming that we have a large file to name as &lt;i style=&quot;font-weight: bold;&quot;&gt;largefile.ext&lt;/i&gt;&amp;nbsp;which we can think of as having more than 1 GB of size and that we wanted it to be split into smaller chunks of &lt;i style=&quot;font-weight: bold;&quot;&gt;300mb&lt;/i&gt;. The below command can be used from the command line&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;ul&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;backgroundColor&amp;quot;:null,&amp;quot;color&amp;quot;:null,&amp;quot;lineHeight&amp;quot;:null,&amp;quot;listStyleType&amp;quot;:null},&amp;quot;li&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;checked&amp;quot;:null,&amp;quot;value&amp;quot;:null,&amp;quot;displayValue&amp;quot;:null,&amp;quot;backgroundColor&amp;quot;:null,&amp;quot;color&amp;quot;:null,&amp;quot;listStyleType&amp;quot;:null}]&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #232629;&quot;&gt;split largefile.ext -b 300m&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Once run, we can use a &lt;i style=&quot;font-weight: bold;&quot;&gt;dir &lt;/i&gt;incase of a windows OS or a &lt;i style=&quot;font-weight: bold;&quot;&gt;ls (or) ls -al&amp;nbsp;&lt;/i&gt;&amp;nbsp;on a linux system that can help us view the list of files that were created in the process of splitting.&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Remarks&lt;/h2&gt;&lt;div&gt;I have been trying to literally open server logs by downloading them from server and given that they were very huge, I had to try with different editors and even if the file was opened, a search could take minutes or move the application (editor) into a frozen state which can take mins to unfreeze or might have to end task and restart.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This solution literally saved a lot of my time. Hope it does for the reader as well&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/2338930528948349273/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2022/06/split-very-large-file-in-to-chunks.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/2338930528948349273'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/2338930528948349273'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2022/06/split-very-large-file-in-to-chunks.html' title='Split a very large file in to chunks '/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-5616978860847902607</id><published>2022-06-13T13:22:00.002+05:30</published><updated>2022-06-13T13:24:26.627+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="apache"/><category scheme="http://www.blogger.com/atom/ns#" term="apache tomcat"/><category scheme="http://www.blogger.com/atom/ns#" term="application.properties"/><category scheme="http://www.blogger.com/atom/ns#" term="http1.1"/><category scheme="http://www.blogger.com/atom/ns#" term="http2"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="spring boot"/><category scheme="http://www.blogger.com/atom/ns#" term="ssl"/><category scheme="http://www.blogger.com/atom/ns#" term="tomcat"/><title type='text'>Upgrade from http1.1 to http2 for Java spring boot applications hosted in tomcat</title><content type='html'>&lt;meta content=&quot;spring boot,apache,tomcat,apache tomcat,http2,http1.1,ssl,application.properties,java&quot; name=&quot;keywords&quot; /&gt;
In this post, we will list down the tasks to be done for enabling the HTTP 2.0 support in spring boot applications which are hosted in Apache tomcat webserver&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Application Level Changes&lt;/div&gt;&lt;div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Spring boot Application Configuration Changes&lt;/h2&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;div data-codeblock=&quot;true&quot; data-en-clipboard=&quot;true&quot; data-pm-slice=&quot;2 1 []&quot; style=&quot;background-color: #fbfaf8; background-position: initial initial; background-repeat: initial initial; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; padding: 8px;&quot;&gt;&lt;div data-plaintext=&quot;true&quot;&gt;server.http2.enabled=true&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;In the spring boot application&#39;s&lt;b&gt;&lt;i&gt; application.properties&lt;/i&gt;&lt;/b&gt; file, we have to add the above line so that Spring boot can add the support for http2&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Tomcat server configuration&lt;/h2&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;In the tomcat web server, we should have &lt;i style=&quot;font-weight: bold;&quot;&gt;SSL &lt;/i&gt;enabled before doing the below change.&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;To start with, we have to shutdown the tomcat server instance that is running&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;CD to the directory that has tomcat installed and cd to the bin directory and run the below command&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;div data-codeblock=&quot;true&quot; data-en-clipboard=&quot;true&quot; data-pm-slice=&quot;2 1 []&quot; style=&quot;background-color: #fbfaf8; background-position: initial initial; background-repeat: initial initial; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; padding: 8px;&quot;&gt;&lt;div data-plaintext=&quot;true&quot;&gt;sh shutdown.sh&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;We have add the &lt;i style=&quot;font-weight: bold;&quot;&gt;UpgradeProtocol&lt;/i&gt;&amp;nbsp;which adds the respective Http2Protocol handler classname to the connector pipeline that enables support for http2.0&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;div data-codeblock=&quot;true&quot; data-en-clipboard=&quot;true&quot; data-pm-slice=&quot;0 1 []&quot; style=&quot;background-color: #fbfaf8; background-position: initial initial; background-repeat: initial initial; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; padding: 8px;&quot;&gt;&lt;div data-plaintext=&quot;true&quot;&gt;&amp;lt;UpgradeProtocol className=&quot;org.apache.coyote.http2.Http2Protocol&quot; /&amp;gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The above &lt;span data-code=&quot;true&quot;&gt;UpgradeProtocol&lt;/span&gt; can be added to the connector as given below&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div data-codeblock=&quot;true&quot; style=&quot;background-color: #fbfaf8; background-position: initial initial; background-repeat: initial initial; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; padding: 8px;&quot;&gt;&lt;div data-plaintext=&quot;true&quot;&gt;&amp;lt;Connector port=&quot;443&quot; protocol=&quot;org.apache.coyote.http11.Http11AprProtocol&quot;&lt;/div&gt;&lt;div data-plaintext=&quot;true&quot;&gt;               maxThreads=&quot;150&quot; SSLEnabled=&quot;true&quot; ...&amp;gt;&lt;/div&gt;&lt;div data-plaintext=&quot;true&quot;&gt;        &amp;lt;UpgradeProtocol className=&quot;org.apache.coyote.http2.Http2Protocol&quot; /&amp;gt;&lt;/div&gt;&lt;div data-plaintext=&quot;true&quot;&gt;&amp;lt;/Connector&amp;gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;The above command has omitted the SSL configuration that is present for brevity.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Once the above are done, we need to stop and start tomcat by running the below commands&lt;/div&gt;&lt;div&gt;1. CD to the directory that has the tomcat server&#39;s &lt;i style=&quot;font-weight: bold;&quot;&gt;bin &lt;/i&gt;directory&lt;/div&gt;&lt;div&gt;2. Run the below command to start tomcat&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;div data-codeblock=&quot;true&quot; data-en-clipboard=&quot;true&quot; data-pm-slice=&quot;2 1 []&quot; style=&quot;background-color: #fbfaf8; background-position: initial initial; background-repeat: initial initial; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; padding: 8px;&quot;&gt;&lt;div data-plaintext=&quot;true&quot;&gt;sh startup.sh&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div data-en-clipboard=&quot;true&quot; data-plaintext=&quot;true&quot; data-pm-slice=&quot;1 1 [&amp;quot;codeblock&amp;quot;,{&amp;quot;style&amp;quot;:null,&amp;quot;codeblock&amp;quot;:true,&amp;quot;textAlign&amp;quot;:null}]&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;Once done, navigate to the browser and open developer tools (F12 in chrome, or right click and choose &quot;Inspect&quot;)&lt;/div&gt;&lt;div&gt;Navigate to the &quot;Network&quot; tab and view the requests that are being sent to the API Service. All of the requests should be sent using http2 identified by &lt;i style=&quot;font-weight: bold;&quot;&gt;h2&lt;/i&gt;&amp;nbsp;in the protocol column.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If you are unable to find the protocol column, on the network tab header columns, right click and choose &lt;b&gt;&lt;i&gt;protocol&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/5616978860847902607/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2022/06/upgrade-from-http11-to-http2-for-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/5616978860847902607'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/5616978860847902607'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2022/06/upgrade-from-http11-to-http2-for-java.html' title='Upgrade from http1.1 to http2 for Java spring boot applications hosted in tomcat'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-3780744569663710185</id><published>2022-05-29T17:10:00.002+05:30</published><updated>2022-05-29T17:10:43.764+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="APIController"/><category scheme="http://www.blogger.com/atom/ns#" term="custom response from fixed class"/><category scheme="http://www.blogger.com/atom/ns#" term="DTO"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="jsonview"/><category scheme="http://www.blogger.com/atom/ns#" term="jsonviews"/><category scheme="http://www.blogger.com/atom/ns#" term="RestController"/><category scheme="http://www.blogger.com/atom/ns#" term="spring boot"/><category scheme="http://www.blogger.com/atom/ns#" term="subset of entity properties"/><title type='text'>Jsonview in Spring boot</title><content type='html'>&lt;meta content=&quot;java,spring boot,jsonview,jsonviews,DTO,APIController,RestController,subset of entity properties,custom response from fixed class&quot; name=&quot;keywords&quot;&gt;
&lt;h1 style=&quot;text-align: left;&quot;&gt;Introduction&lt;/h1&gt;&lt;p style=&quot;text-align: left;&quot;&gt;There are scenarios where we have a DTO or a model class that contains a collection of properties and there might be some endpoints that require a subset of them and some other endpoint that might need all of them.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Example: Consider a scenario where we need a list of Categories in a dropdown and we have an API that gets all the categories from the static masterdata and need to send to the UI in response to an API call.&lt;/p&gt;&lt;h1&gt;Problem Statement&amp;nbsp;&lt;/h1&gt;&lt;p style=&quot;text-align: left;&quot;&gt;We might choose to use a `Map` data type so that we send out the key-value pairs to the database or to choose to build a custom DTO with only the Id, name of the categories.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;In a longer run, if we opt to use multiple DTO in the source, sooner there will be a very large collection of DTO classes that represent subset of a static data.&lt;/p&gt;&lt;h1 style=&quot;text-align: left;&quot;&gt;Solution&lt;/h1&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Rather than ending up with a large number of such DTO classes, we can use a JSON View. This helps us have a single class and control which fields are part of which view.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Example: We can have a dropdown view in categories that will have an Id,Name alone. Similarly, there might be a grid view which might need some other subset of properties, which can be referred through a view.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;This helps us a lot because we no longer have to worry about the multiple DTO, but we can be able to view in a single class definition, which properties are used by which parts of the application.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;Below given is a sample application that illustrates the above concepts.&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;The Categories Class&lt;/p&gt;&lt;pre style=&quot;background-color: white; font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 9.8pt;&quot;&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;public class &lt;/span&gt;Categories &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;implements &lt;/span&gt;Serializable {&lt;br /&gt;   &lt;br /&gt;    &lt;span style=&quot;color: olive;&quot;&gt;@JsonView&lt;/span&gt;({CategoryViews.CategoryCollectionView.&lt;span style=&quot;color: navy; font-size: 9.8pt; font-weight: bold;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;font-size: 9.8pt;&quot;&gt;, CategoryViews.&lt;/span&gt;CategoryExecutionView.&lt;span style=&quot;color: navy; font-size: 9.8pt; font-weight: bold;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;font-size: 9.8pt;&quot;&gt;})&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 9.8pt;&quot;&gt;    &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;private &lt;/span&gt;Long &lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;id &lt;/span&gt;= &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;null&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: olive;&quot;&gt;@NotNull&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: olive;&quot;&gt;    @JsonView&lt;/span&gt;({CategoryViews.CategoryCollectionView.&lt;span style=&quot;color: navy; font-size: 9.8pt; font-weight: bold;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;font-size: 9.8pt;&quot;&gt;, &lt;/span&gt;CategoryViews.CategoryExecutionView.&lt;span style=&quot;color: navy; font-size: 9.8pt; font-weight: bold;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;font-size: 9.8pt;&quot;&gt;})&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 9.8pt;&quot;&gt;    &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;private &lt;/span&gt;String &lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;name &lt;/span&gt;= &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;null&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: olive;&quot;&gt;@JsonView&lt;/span&gt;(CategoryViews.CategoryCollectionView.&lt;span style=&quot;color: navy; font-size: 9.8pt; font-weight: bold;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;font-size: 9.8pt;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;private &lt;/span&gt;Long &lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;createdBy &lt;/span&gt;= &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;null&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: olive;&quot;&gt;@JsonView&lt;/span&gt;(CategoryViews.CategoryCollectionView.&lt;span style=&quot;color: navy; font-size: 9.8pt; font-weight: bold;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;font-size: 9.8pt;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;private &lt;/span&gt;Date &lt;span style=&quot;color: #660e7a; font-weight: bold;&quot;&gt;createdOn &lt;/span&gt;= &lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;new &lt;/span&gt;Date();&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: olive;&quot;&gt;@JsonView&lt;/span&gt;(CategoryViews.CategoryExecutionView.&lt;span style=&quot;color: navy; font-size: 9.8pt; font-weight: bold;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;font-size: 9.8pt;&quot;&gt;)&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 9.8pt;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;private boolean &lt;span style=&quot;background-color: transparent; color: #660e7a; font-size: 9.8pt; font-weight: bold;&quot;&gt;executable &lt;/span&gt;&lt;span style=&quot;font-size: 9.8pt;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: navy; font-size: 9.8pt; font-weight: bold;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;font-size: 9.8pt;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 9.8pt;&quot;&gt;}&amp;nbsp;&lt;/pre&gt;&lt;p style=&quot;text-align: left;&quot;&gt;The CategoryView are defined like below&lt;/p&gt;&lt;pre style=&quot;background-color: white; font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 9.8pt;&quot;&gt;&lt;pre style=&quot;font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 9.8pt;&quot;&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;public interface &lt;/span&gt;CategoryViews{&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: grey; font-style: italic;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;interface &lt;/span&gt;CategoryCollectionView{&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;span style=&quot;color: grey; font-style: italic;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: grey; font-style: italic;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;interface &lt;/span&gt;CategoryExecutionView{&lt;/pre&gt;&lt;pre style=&quot;font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 9.8pt;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 9.8pt;&quot;&gt;}&lt;/pre&gt;&lt;/pre&gt;&lt;p style=&quot;text-align: left;&quot;&gt;The usage in an API controller&lt;/p&gt;&lt;pre style=&quot;background-color: white; font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 9.8pt;&quot;&gt;&lt;span style=&quot;color: olive;&quot;&gt;@GetMapping&lt;/span&gt;(value = &lt;span style=&quot;color: green; font-weight: bold;&quot;&gt;&quot;categories/forExecution&quot;&lt;/span&gt;, produces = {&lt;span style=&quot;color: #660e7a; font-style: italic; font-weight: bold;&quot;&gt;APPLICATION_JSON_VALUE&lt;/span&gt;})&lt;br /&gt;&lt;span style=&quot;color: olive;&quot;&gt;@JsonView&lt;/span&gt;(CategoryViews.CategoryExecutionView.&lt;span style=&quot;color: navy; font-size: 9.8pt; font-weight: bold;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;font-size: 9.8pt;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: navy; font-weight: bold;&quot;&gt;public &lt;/span&gt;ResponseEntity&amp;lt;List&amp;lt;Categories&amp;gt;&amp;gt; getFilterExecutableCategories(... ) { ... }&lt;br /&gt;&lt;/pre&gt;&lt;h1 style=&quot;text-align: left;&quot;&gt;Remarks&lt;/h1&gt;&lt;div&gt;Here, we have used a view defined in the interface &lt;i style=&quot;font-weight: bold;&quot;&gt;CategoryViews&lt;/i&gt;&amp;nbsp;that can be used to define the multiple representation of the data.&lt;/div&gt;&lt;div&gt;We have 2 view namely &lt;b&gt;&lt;i&gt;CategoryCollectionView &amp;amp; CategoryExecutionView.&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;We have decorated our &lt;i style=&quot;font-weight: bold;&quot;&gt;Categories&lt;/i&gt;&amp;nbsp;class fields with the respective views based on the requirement.&lt;/div&gt;&lt;div&gt;These are seen in the code snippet given above.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Once the mappings are done, we can use the API controllers and decorate the endpoints with the respective JsonViews.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This helps spring boot to apply the appropriate serialization process to render the selected fields alone in the response rather than the whole set of properties in the entity.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This helps reduce the volume of data transferred over the wire from the API to the UI or mobile front-end. This also helps the consumer get a clear picture on what fields they are needing and get only those rather than send in full and clutter the code base to filter out the required propertiess.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/3780744569663710185/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2022/05/jsonview-in-spring-boot.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/3780744569663710185'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/3780744569663710185'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2022/05/jsonview-in-spring-boot.html' title='Jsonview in Spring boot'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-6828804078248951056</id><published>2022-05-21T18:15:00.006+05:30</published><updated>2022-05-25T17:54:34.629+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="exception"/><category scheme="http://www.blogger.com/atom/ns#" term="exceptionhandler"/><category scheme="http://www.blogger.com/atom/ns#" term="Executors"/><category scheme="http://www.blogger.com/atom/ns#" term="ExecutorService"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="RuntimeException"/><category scheme="http://www.blogger.com/atom/ns#" term="setDefaultUncaughtExceptionHandler"/><category scheme="http://www.blogger.com/atom/ns#" term="singleton"/><category scheme="http://www.blogger.com/atom/ns#" term="spring boot"/><category scheme="http://www.blogger.com/atom/ns#" term="SupportNotificationExceptionHandler"/><category scheme="http://www.blogger.com/atom/ns#" term="thread"/><category scheme="http://www.blogger.com/atom/ns#" term="UncaughtExceptionHandler"/><title type='text'>Handling exceptions in the Executor service threads in Java </title><content type='html'>&lt;meta content=&#39;exception,singleton,spring boot,java,RuntimeException,exceptionhandler,SupportNotificationExceptionHandler,setDefaultUncaughtExceptionHandler,ExecutorService,thread,Executors,UncaughtExceptionHandler&#39; name=&#39;keywords&#39;/&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;Introduction&lt;/h2&gt;&lt;div&gt;This is a continuation post on the exception handling strategies in the threads in Java.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;For Introduction, please read &lt;a href=&quot;https://saravanandorai.blogspot.com/2022/05/handling-exceptions-in-threads-in-java.html&quot; target=&quot;_blank&quot;&gt;this post&lt;/a&gt;&lt;/div&gt;&lt;div&gt;The second post is &lt;a href=&quot;https://saravanandorai.blogspot.com/2022/05/handling-exceptions-at-thread-level-in.html&quot; target=&quot;_blank&quot;&gt;available here&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This post addresses the problem statement &quot;How to use the exception handlers in the threads spawned by the Executor Service in Java?&quot;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Not all times, we will be using &lt;i style=&quot;font-weight: bold;&quot;&gt;Thread&lt;/i&gt;&amp;nbsp;classes to run our threads because we have to manage a lot of the underlying logic for managing threads. There is &lt;i style=&quot;font-weight: bold;&quot;&gt;ExecutorService &lt;/i&gt;in Java which comes to the rescue for the above problem.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In the previous posts, we have discussed on how to handle the exceptions in plain threads. However, when using executor service, we do not create / manage threads, so how do we handle exception in this case.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We have a &lt;i style=&quot;font-weight: bold;&quot;&gt;ThreadFactory&amp;nbsp;&lt;/i&gt;&amp;nbsp;as an argument which can be used to customize the way threads are created for use within the &lt;i style=&quot;font-weight: bold;&quot;&gt;ExecutorService&lt;/i&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The below snippet of code leverages this feature to illustrate the exception handling, wherein we create a factory and internally we manage the thread and set its &lt;i style=&quot;font-weight: bold;&quot;&gt;ExceptionHandler&lt;/i&gt;&amp;nbsp;and allow the executor service to use this thread so that it can bring in threads with exception handlers customized.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre style=&quot;background-color: #ece3db; color: #585858; font-family: &amp;quot;Comic Mono&amp;quot;, monospace; font-size: 12pt;&quot;&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;class &lt;/span&gt;&lt;span style=&quot;color: #76690b;&quot;&gt;ExceptionHandlingThreadFactory &lt;/span&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;extends &lt;/span&gt;&lt;span style=&quot;color: #76690b;&quot;&gt;NamedThreadFactory &lt;/span&gt;{&lt;br /&gt;    &lt;span style=&quot;color: #367a7f;&quot;&gt;@Override&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #367a7f;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;color: #76690b;&quot;&gt;Thread &lt;/span&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;newThread&lt;/span&gt;(&lt;span style=&quot;color: #737373;&quot;&gt;Runnable &lt;/span&gt;r) {&lt;br /&gt;        &lt;span style=&quot;color: #76690b;&quot;&gt;ct&lt;/span&gt;++;&lt;br /&gt;        &lt;span style=&quot;color: #76690b;&quot;&gt;Thread &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;t &lt;/span&gt;= &lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;Thread&lt;/span&gt;(r, format(&lt;span style=&quot;color: #3b4bab;&quot;&gt;&quot;%s%d&quot;&lt;/span&gt;, &lt;span style=&quot;color: #0073b5;&quot;&gt;name&lt;/span&gt;, &lt;span style=&quot;color: #76690b;&quot;&gt;ct&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: #737373;&quot;&gt;t&lt;/span&gt;.&lt;span style=&quot;color: #737373;&quot;&gt;setUncaughtExceptionHandler&lt;/span&gt;((t1, e) -&amp;gt; &lt;span style=&quot;color: #76690b;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color: #660e7a; font-style: italic; font-weight: bold;&quot;&gt;out&lt;/span&gt;.&lt;span style=&quot;color: #737373;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;color: #3b4bab;&quot;&gt;&quot;Handling the exception in factory for thread: &quot; &lt;/span&gt;+ t1.&lt;span style=&quot;color: #737373;&quot;&gt;getName&lt;/span&gt;() + &lt;span style=&quot;color: #3b4bab;&quot;&gt;&quot; and exception is: &quot; &lt;/span&gt;+ e.&lt;span style=&quot;color: #737373;&quot;&gt;getMessage&lt;/span&gt;()));&lt;br /&gt;        &lt;span style=&quot;color: #ad4271;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;t&lt;/span&gt;;&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;The above code illustrates the user of the Threadfactory (in the above case the NamedThreadFactory is actually implementing ThreadFactory as given below)&lt;/div&gt;&lt;div&gt;&lt;pre style=&quot;background-color: #ece3db; color: #585858; font-family: &amp;quot;Comic Mono&amp;quot;, monospace; font-size: 9.8pt;&quot;&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;public class &lt;/span&gt;&lt;span style=&quot;color: #76690b;&quot;&gt;NamedThreadFactory &lt;/span&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;implements &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ThreadFactory &lt;/span&gt;{&lt;br /&gt;    &lt;span style=&quot;color: #ad4271;&quot;&gt;protected static int &lt;/span&gt;&lt;span style=&quot;color: #76690b;&quot;&gt;ct &lt;/span&gt;= &lt;span style=&quot;color: #a74f31;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;    &lt;span style=&quot;color: #ad4271;&quot;&gt;protected &lt;/span&gt;&lt;span style=&quot;color: #76690b;&quot;&gt;String &lt;/span&gt;&lt;span style=&quot;color: #0073b5;&quot;&gt;name &lt;/span&gt;= &lt;span style=&quot;color: #3b4bab;&quot;&gt;&quot;My_NamedThread_&quot;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #367a7f;&quot;&gt;@Override&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #367a7f;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;color: #76690b;&quot;&gt;Thread &lt;/span&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;newThread&lt;/span&gt;(&lt;span style=&quot;color: #737373;&quot;&gt;Runnable &lt;/span&gt;r) {&lt;br /&gt;        &lt;span style=&quot;color: #76690b;&quot;&gt;ct&lt;/span&gt;++;&lt;br /&gt;        &lt;span style=&quot;color: #ad4271;&quot;&gt;return new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;Thread&lt;/span&gt;(r, format(&lt;span style=&quot;color: #3b4bab;&quot;&gt;&quot;%s%d&quot;&lt;/span&gt;, &lt;span style=&quot;color: #0073b5;&quot;&gt;name&lt;/span&gt;, &lt;span style=&quot;color: #76690b;&quot;&gt;ct&lt;/span&gt;));&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;Now, that we have the factories in place, how do we use them, below given snippet of code illustrates how it is done.&lt;/div&gt;&lt;div&gt;&lt;pre style=&quot;background-color: #ece3db; color: #585858; font-family: &amp;quot;Comic Mono&amp;quot;, monospace; font-size: 12pt;&quot;&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ExecutorService service &lt;/span&gt;= &lt;span style=&quot;color: #76690b;&quot;&gt;Executors&lt;/span&gt;.newCachedThreadPool(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ExceptionHandlingThreadFactory&lt;/span&gt;());&lt;br /&gt;&lt;span style=&quot;color: #737373;&quot;&gt;service&lt;/span&gt;.&lt;span style=&quot;color: #737373;&quot;&gt;execute&lt;/span&gt;(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ExceptionLeakingTask&lt;/span&gt;());&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/6828804078248951056/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2022/05/handling-exceptions-in-executor-service.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/6828804078248951056'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/6828804078248951056'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2022/05/handling-exceptions-in-executor-service.html' title='Handling exceptions in the Executor service threads in Java '/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-3603901849307108008</id><published>2022-05-21T17:52:00.005+05:30</published><updated>2022-05-25T17:54:59.267+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="exception"/><category scheme="http://www.blogger.com/atom/ns#" term="exceptionhandler"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="RuntimeException"/><category scheme="http://www.blogger.com/atom/ns#" term="setDefaultUncaughtExceptionHandler"/><category scheme="http://www.blogger.com/atom/ns#" term="singleton"/><category scheme="http://www.blogger.com/atom/ns#" term="singletons"/><category scheme="http://www.blogger.com/atom/ns#" term="spring"/><category scheme="http://www.blogger.com/atom/ns#" term="spring boot"/><category scheme="http://www.blogger.com/atom/ns#" term="SupportNotificationExceptionHandler"/><category scheme="http://www.blogger.com/atom/ns#" term="thread"/><category scheme="http://www.blogger.com/atom/ns#" term="threads"/><category scheme="http://www.blogger.com/atom/ns#" term="UncaughtExceptionHandler"/><title type='text'>Handling exceptions at thread level in Java</title><content type='html'>&lt;meta content=&#39;exception,singleton,SupportNotificationExceptionHandler,setDefaultUncaughtExceptionHandler,threads,thread,singletons,spring,spring boot,java,RuntimeException,exceptionhandler,UncaughtExceptionHandler&#39; name=&#39;keywords&#39;/&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;Introduction&lt;/h2&gt;&lt;div&gt;This is a continuation to the post on exception handling on threads. For those interested in the background, please visit &lt;a href=&quot;https://saravanandorai.blogspot.com/2022/05/handling-exceptions-in-threads-in-java.html&quot; target=&quot;_blank&quot;&gt;this link&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This post discusses on the topic &quot;Can I use separate exception handlers for threads performing mission critical tasks vs non trivial tasks?&quot;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h1 style=&quot;text-align: left;&quot;&gt;Per-Thread Exception Handler&lt;/h1&gt;&lt;div&gt;Let&#39;s us assume that we built a handler that wants to notify the support team that something has gone wrong in some special thread processing, like the one below (not really notifying anyone but helps correlate the context)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre style=&quot;background-color: #ece3db; color: #585858; font-family: &amp;quot;Comic Mono&amp;quot;, monospace; font-size: 9.8pt;&quot;&gt;&lt;br /&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;class &lt;/span&gt;&lt;span style=&quot;color: #76690b;&quot;&gt;SupportNotificationExceptionHandler &lt;/span&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;implements &lt;/span&gt;&lt;span style=&quot;color: #76690b;&quot;&gt;Thread&lt;/span&gt;.&lt;span style=&quot;color: #737373;&quot;&gt;UncaughtExceptionHandler &lt;/span&gt;{&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #367a7f;&quot;&gt;@Override&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #367a7f;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;public void uncaughtException&lt;/span&gt;(&lt;span style=&quot;color: #76690b;&quot;&gt;Thread &lt;/span&gt;t, &lt;span style=&quot;color: #76690b;&quot;&gt;Throwable &lt;/span&gt;e) {&lt;br /&gt;        &lt;span style=&quot;color: #737373;&quot;&gt;notifySupport&lt;/span&gt;(t, e);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #ad4271;&quot;&gt;private void notifySupport&lt;/span&gt;(&lt;span style=&quot;color: #76690b;&quot;&gt;Thread &lt;/span&gt;t, &lt;span style=&quot;color: #76690b;&quot;&gt;Throwable &lt;/span&gt;e) {&lt;br /&gt;        &lt;span style=&quot;color: #76690b;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color: #660e7a; font-style: italic; font-weight: bold;&quot;&gt;out&lt;/span&gt;.&lt;span style=&quot;color: #737373;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;color: #3b4bab;&quot;&gt;&quot;Notified support team on: &quot; &lt;/span&gt;+ e.&lt;span style=&quot;color: #737373;&quot;&gt;getMessage&lt;/span&gt;() + &lt;span style=&quot;color: #3b4bab;&quot;&gt;&quot; raised from : &quot; &lt;/span&gt;+ t.&lt;span style=&quot;color: #737373;&quot;&gt;getName&lt;/span&gt;());&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;Let us now apply the above special handler to specific threads in the application. Here we are opting for support team to be notified for any exception in main thread and in one other specific thread.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Refer the snippet of code below,&lt;/div&gt;&lt;div&gt;&lt;pre style=&quot;background-color: #ece3db; color: #585858; font-family: &amp;quot;Comic Mono&amp;quot;, monospace; font-size: 9.8pt;&quot;&gt;&lt;br /&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;public class &lt;/span&gt;&lt;span style=&quot;color: #76690b;&quot;&gt;ThreadSpecificHandler &lt;/span&gt;{&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #ad4271;&quot;&gt;public static void main&lt;/span&gt;(&lt;span style=&quot;color: #76690b;&quot;&gt;String&lt;/span&gt;[] args) {&lt;br /&gt;        &lt;span style=&quot;color: #76690b;&quot;&gt;Thread&lt;/span&gt;.currentThread().&lt;span style=&quot;color: #737373;&quot;&gt;setUncaughtExceptionHandler&lt;/span&gt;(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;SupportNotificationExceptionHandler&lt;/span&gt;());&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #76690b;&quot;&gt;Thread&lt;/span&gt;.setDefaultUncaughtExceptionHandler(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ThreadExceptionHandler&lt;/span&gt;(&lt;span style=&quot;color: #3b4bab;&quot;&gt;&quot;DEFAULT&quot;&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;Thread&lt;/span&gt;(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ExceptionLeakingTask&lt;/span&gt;()).&lt;span style=&quot;color: #737373;&quot;&gt;start&lt;/span&gt;();&lt;br /&gt;        &lt;span style=&quot;color: #76690b;&quot;&gt;Thread &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;t2 &lt;/span&gt;= &lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;Thread&lt;/span&gt;(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ExceptionLeakingTask&lt;/span&gt;());&lt;br /&gt;        &lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;Thread&lt;/span&gt;(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ExceptionLeakingTask&lt;/span&gt;()).&lt;span style=&quot;color: #737373;&quot;&gt;start&lt;/span&gt;();&lt;br /&gt;        &lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;Thread&lt;/span&gt;(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ExceptionLeakingTask&lt;/span&gt;()).&lt;span style=&quot;color: #737373;&quot;&gt;start&lt;/span&gt;();&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #737373;&quot;&gt;t2&lt;/span&gt;.&lt;span style=&quot;color: #737373;&quot;&gt;setUncaughtExceptionHandler&lt;/span&gt;(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;SupportNotificationExceptionHandler&lt;/span&gt;());&lt;br /&gt;        &lt;span style=&quot;color: #737373;&quot;&gt;t2&lt;/span&gt;.&lt;span style=&quot;color: #737373;&quot;&gt;start&lt;/span&gt;();&lt;br /&gt;        &lt;span style=&quot;color: #ad4271;&quot;&gt;throw new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ArithmeticException&lt;/span&gt;(&lt;span style=&quot;color: #3b4bab;&quot;&gt;&quot;whatever&quot;&lt;/span&gt;);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;As given in the snippet above, we are using the &lt;b style=&quot;font-style: italic;&quot;&gt;SupportNotificationExceptionHandler &lt;/b&gt;for the main thread and 2nd thread (&lt;i style=&quot;font-weight: bold;&quot;&gt;t2)&lt;/i&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Whenever an exception is getting raised in the main and t2, they are notified to the support team, remaining ones are all using the default handler to log to the console and continue.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This illustrates how we can build the handlers specific for the collection of threads based on the business critical threading tasks vs non trivial threading tasks&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Below given is the snippet where we have a single handler to be used in many threads&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre style=&quot;background-color: #ece3db; color: #585858; font-family: &#39;Comic Mono&#39;,monospace; font-size: 9.8pt;&quot;&gt;&lt;br /&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;public static void main&lt;/span&gt;(&lt;span style=&quot;color: #76690b;&quot;&gt;String&lt;/span&gt;[] args) {&lt;br /&gt;    &lt;span style=&quot;color: #76690b;&quot;&gt;SupportNotificationExceptionHandler &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;supportNotificationExceptionHandler &lt;/span&gt;= &lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;SupportNotificationExceptionHandler&lt;/span&gt;();&lt;br /&gt;    &lt;span style=&quot;color: #76690b;&quot;&gt;Thread&lt;/span&gt;.currentThread().&lt;span style=&quot;color: #737373;&quot;&gt;setUncaughtExceptionHandler&lt;/span&gt;(&lt;span style=&quot;color: #737373;&quot;&gt;supportNotificationExceptionHandler&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #76690b;&quot;&gt;Thread&lt;/span&gt;.setDefaultUncaughtExceptionHandler(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ThreadExceptionHandler&lt;/span&gt;(&lt;span style=&quot;color: #3b4bab;&quot;&gt;&quot;DEFAULT&quot;&lt;/span&gt;));&lt;br /&gt;    &lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;Thread&lt;/span&gt;(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ExceptionLeakingTask&lt;/span&gt;()).&lt;span style=&quot;color: #737373;&quot;&gt;start&lt;/span&gt;();&lt;br /&gt;    &lt;span style=&quot;color: #76690b;&quot;&gt;Thread &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;t2 &lt;/span&gt;= &lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;Thread&lt;/span&gt;(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ExceptionLeakingTask&lt;/span&gt;());&lt;br /&gt;    &lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;Thread&lt;/span&gt;(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ExceptionLeakingTask&lt;/span&gt;()).&lt;span style=&quot;color: #737373;&quot;&gt;start&lt;/span&gt;();&lt;br /&gt;    &lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;Thread&lt;/span&gt;(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ExceptionLeakingTask&lt;/span&gt;()).&lt;span style=&quot;color: #737373;&quot;&gt;start&lt;/span&gt;();&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #737373;&quot;&gt;t2&lt;/span&gt;.&lt;span style=&quot;color: #737373;&quot;&gt;setUncaughtExceptionHandler&lt;/span&gt;(&lt;span style=&quot;color: #737373;&quot;&gt;supportNotificationExceptionHandler&lt;/span&gt;);&lt;br /&gt;    &lt;span style=&quot;color: #737373;&quot;&gt;t2&lt;/span&gt;.&lt;span style=&quot;color: #737373;&quot;&gt;start&lt;/span&gt;();&lt;br /&gt;    &lt;span style=&quot;color: #ad4271;&quot;&gt;throw new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ArithmeticException&lt;/span&gt;(&lt;span style=&quot;color: #3b4bab;&quot;&gt;&quot;whatever&quot;&lt;/span&gt;);&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;When using a spring framework like Spring boot, we can have the handlers autowired as singletons, thereby eliminating the new instance creation in the code base.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/3603901849307108008/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2022/05/handling-exceptions-at-thread-level-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/3603901849307108008'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/3603901849307108008'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2022/05/handling-exceptions-at-thread-level-in.html' title='Handling exceptions at thread level in Java'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4074627129522097342.post-2004838118941335572</id><published>2022-05-21T17:37:00.005+05:30</published><updated>2022-05-25T17:55:22.881+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="exception"/><category scheme="http://www.blogger.com/atom/ns#" term="exceptionhandler"/><category scheme="http://www.blogger.com/atom/ns#" term="handle exceptions"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="Runnable"/><category scheme="http://www.blogger.com/atom/ns#" term="RuntimeException"/><category scheme="http://www.blogger.com/atom/ns#" term="setDefaultUncaughtExceptionHandler"/><category scheme="http://www.blogger.com/atom/ns#" term="thread"/><category scheme="http://www.blogger.com/atom/ns#" term="threads"/><category scheme="http://www.blogger.com/atom/ns#" term="UncaughtExceptionHandler"/><title type='text'>Handling Exceptions in Threads in Java</title><content type='html'>&lt;meta content=&#39;exception,java,handle exceptions,RuntimeException,exceptionhandler,setDefaultUncaughtExceptionHandler,Runnable,threads,thread,UncaughtExceptionHandler&#39; name=&#39;keywords&#39;/&gt;
&lt;h1 style=&quot;text-align: left;&quot;&gt;Introduction&lt;/h1&gt;&lt;div&gt;Exception handling is very critical to any application and any language that was used to develop. This helps the following stakeholders&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Stakeholders&lt;/h2&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;End-User:&lt;/h3&gt;&lt;p style=&quot;text-align: left;&quot;&gt;A graceful message that indicates that something has gone wrong in the system due to some wrong input or due to some internal fault&lt;/p&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Developer&lt;/h3&gt;&lt;div&gt;A clean way to get to know which line of code caused the exception and the stack trace that can help us reach to the points impacted&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Support Team&lt;/h3&gt;&lt;div&gt;A helpful hint that they can try to verify and resolve if it is something within their reach or to escalate to the product team&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;SRE (Site Reliability Engineering)&lt;/h3&gt;&lt;div&gt;An indication of how far the application is performing w.r.to being reliable to the end-users and how faults are handled or tolerated etc..&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Problem Statement&lt;/h2&gt;&lt;div&gt;When we use threads to get the job done for performing some intensive task (computation or Network intensive tasks), it becomes difficult to track down on the exceptions.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This post is one in a series of posts that will talk about the exception handling strategies w.r.to the threading and tasks in Java.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Let us consider the below given simple app that has multiple threads running tasks. Here, the task is to throw exception which is for demonstration, which can be correlated in realtime with any 3rd party service / external service invocation that might throw exceptions.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre style=&quot;background-color: #ece3db; color: #585858; font-family: &amp;quot;Comic Mono&amp;quot;, monospace; font-size: 9.8pt;&quot;&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;package &lt;/span&gt;&lt;span style=&quot;color: #76690b;&quot;&gt;com.ds.mt.exceptions.handling&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;public class &lt;/span&gt;&lt;span style=&quot;color: #76690b;&quot;&gt;ExceptionLeaking &lt;/span&gt;{&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #ad4271;&quot;&gt;public static void main&lt;/span&gt;(&lt;span style=&quot;color: #76690b;&quot;&gt;String&lt;/span&gt;[] args) {&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: darkgrey; font-style: italic;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;try &lt;/span&gt;{&lt;br /&gt;            &lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;Thread&lt;/span&gt;(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ExceptionLeakingTask&lt;/span&gt;()).&lt;span style=&quot;color: #737373;&quot;&gt;start&lt;/span&gt;();&lt;br /&gt;            &lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;Thread&lt;/span&gt;(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ExceptionLeakingTask&lt;/span&gt;()).&lt;span style=&quot;color: #737373;&quot;&gt;start&lt;/span&gt;();&lt;br /&gt;            &lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;Thread&lt;/span&gt;(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ExceptionLeakingTask&lt;/span&gt;()).&lt;span style=&quot;color: #737373;&quot;&gt;start&lt;/span&gt;();&lt;br /&gt;            &lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;Thread&lt;/span&gt;(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ExceptionLeakingTask&lt;/span&gt;()).&lt;span style=&quot;color: #737373;&quot;&gt;start&lt;/span&gt;();&lt;br /&gt;        } &lt;span style=&quot;color: #ad4271;&quot;&gt;catch &lt;/span&gt;(&lt;span style=&quot;color: #76690b;&quot;&gt;Exception &lt;/span&gt;e) {&lt;br /&gt;            &lt;span style=&quot;color: darkgrey; font-style: italic;&quot;&gt;//this catch block does not get executed as the exceptions are thrown inside threads (not the main thread)&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: darkgrey; font-style: italic;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #76690b;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color: #660e7a; font-style: italic; font-weight: bold;&quot;&gt;out&lt;/span&gt;.&lt;span style=&quot;color: #737373;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;color: #3b4bab;&quot;&gt;&quot;Executing the handler for the thread exceptions&quot;&lt;/span&gt;);&lt;br /&gt;            e.&lt;span style=&quot;color: #737373;&quot;&gt;printStackTrace&lt;/span&gt;();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;class &lt;/span&gt;&lt;span style=&quot;color: #76690b;&quot;&gt;ExceptionLeakingTask &lt;/span&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;implements &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;Runnable &lt;/span&gt;{&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #367a7f;&quot;&gt;@Override&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #367a7f;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;public void run&lt;/span&gt;() {&lt;br /&gt;        &lt;span style=&quot;color: #ad4271;&quot;&gt;throw new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;RuntimeException&lt;/span&gt;(&lt;span style=&quot;color: #3b4bab;&quot;&gt;&quot;Hello World!!!&quot;&lt;/span&gt;);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;As mentioned in the comments above, the exceptions are raised in the task that is run inside a thread and the handler is in the main method that wraps all the threads.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;However, in runtime, the exception handling &lt;i style=&quot;font-weight: bold;&quot;&gt;catch&lt;/i&gt;&amp;nbsp;block does not get executed as the exceptions are not thrown in the main thread, which causes the application to break irrespective of having &lt;i style=&quot;font-weight: bold;&quot;&gt;try...catch..&lt;/i&gt;&amp;nbsp;blocks in place.&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Solution&lt;/h2&gt;&lt;div&gt;&lt;pre style=&quot;background-color: #ece3db; color: #585858; font-family: &amp;quot;Comic Mono&amp;quot;, monospace; font-size: 9.8pt;&quot;&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;package &lt;/span&gt;&lt;span style=&quot;color: #76690b;&quot;&gt;com.ds.mt.exceptions.handling&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;public class &lt;/span&gt;&lt;span style=&quot;color: #76690b;&quot;&gt;ExceptionLeaking &lt;/span&gt;{&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #ad4271;&quot;&gt;public static void main&lt;/span&gt;(&lt;span style=&quot;color: #76690b;&quot;&gt;String&lt;/span&gt;[] args) {&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #76690b;&quot;&gt;Thread&lt;/span&gt;.setDefaultUncaughtExceptionHandler(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ThreadExceptionHandler&lt;/span&gt;(&lt;span style=&quot;color: #3b4bab;&quot;&gt;&quot;DEFAULT&quot;&lt;/span&gt;));&lt;br /&gt;&lt;span style=&quot;color: darkgrey; font-style: italic;&quot;&gt;//      Thread.setDefaultUncaughtExceptionHandler((t, e) -&amp;gt; System.out.println(&quot;Exception raised from : &quot; + t.getName() + &quot; and exception is: &quot; + e.getMessage()));&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: darkgrey; font-style: italic;&quot;&gt;       &lt;/span&gt;&lt;br /&gt;         &lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;Thread&lt;/span&gt;(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ExceptionLeakingTask&lt;/span&gt;()).&lt;span style=&quot;color: #737373;&quot;&gt;start&lt;/span&gt;();&lt;br /&gt;         &lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;Thread&lt;/span&gt;(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ExceptionLeakingTask&lt;/span&gt;()).&lt;span style=&quot;color: #737373;&quot;&gt;start&lt;/span&gt;();&lt;br /&gt;         &lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;Thread&lt;/span&gt;(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ExceptionLeakingTask&lt;/span&gt;()).&lt;span style=&quot;color: #737373;&quot;&gt;start&lt;/span&gt;();&lt;br /&gt;         &lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;Thread&lt;/span&gt;(&lt;span style=&quot;color: #ad4271;&quot;&gt;new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;ExceptionLeakingTask&lt;/span&gt;()).&lt;span style=&quot;color: #737373;&quot;&gt;start&lt;/span&gt;();&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;class &lt;/span&gt;&lt;span style=&quot;color: #76690b;&quot;&gt;ThreadExceptionHandler &lt;/span&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;implements &lt;/span&gt;&lt;span style=&quot;color: #76690b;&quot;&gt;Thread&lt;/span&gt;.&lt;span style=&quot;color: #737373;&quot;&gt;UncaughtExceptionHandler &lt;/span&gt;{&lt;br /&gt;    &lt;span style=&quot;color: #ad4271;&quot;&gt;private final &lt;/span&gt;&lt;span style=&quot;color: #76690b;&quot;&gt;String &lt;/span&gt;&lt;span style=&quot;color: #0073b5;&quot;&gt;instanceId&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #ad4271;&quot;&gt;public ThreadExceptionHandler&lt;/span&gt;(&lt;span style=&quot;color: #76690b;&quot;&gt;String &lt;/span&gt;instanceId) {&lt;br /&gt;        &lt;span style=&quot;color: #ad4271;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #0073b5;&quot;&gt;instanceId &lt;/span&gt;= instanceId;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #367a7f;&quot;&gt;@Override&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #367a7f;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;public void uncaughtException&lt;/span&gt;(&lt;span style=&quot;color: #76690b;&quot;&gt;Thread &lt;/span&gt;t, &lt;span style=&quot;color: #76690b;&quot;&gt;Throwable &lt;/span&gt;e) {&lt;br /&gt;        &lt;span style=&quot;color: #76690b;&quot;&gt;System&lt;/span&gt;.&lt;span style=&quot;color: #660e7a; font-style: italic; font-weight: bold;&quot;&gt;out&lt;/span&gt;.&lt;span style=&quot;color: #737373;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;color: #3b4bab;&quot;&gt;&quot;Exception raised from : &quot; &lt;/span&gt;+ t.&lt;span style=&quot;color: #737373;&quot;&gt;getName&lt;/span&gt;() + &lt;span style=&quot;color: #3b4bab;&quot;&gt;&quot; inside instance: &quot; &lt;/span&gt;+ &lt;span style=&quot;color: #0073b5;&quot;&gt;instanceId &lt;/span&gt;+ &lt;span style=&quot;color: #3b4bab;&quot;&gt;&quot; and exception is: &quot; &lt;/span&gt;+ e.&lt;span style=&quot;color: #737373;&quot;&gt;getMessage&lt;/span&gt;());&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;class &lt;/span&gt;&lt;span style=&quot;color: #76690b;&quot;&gt;ExceptionLeakingTask &lt;/span&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;implements &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;Runnable &lt;/span&gt;{&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #367a7f;&quot;&gt;@Override&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #367a7f;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #ad4271;&quot;&gt;public void run&lt;/span&gt;() {&lt;br /&gt;        &lt;span style=&quot;color: #ad4271;&quot;&gt;throw new &lt;/span&gt;&lt;span style=&quot;color: #737373;&quot;&gt;RuntimeException&lt;/span&gt;(&lt;span style=&quot;color: #3b4bab;&quot;&gt;&quot;Hello World!!!&quot;&lt;/span&gt;);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In the above sample code, we have setup a exception handler and wired it to the Thread class Exceptiohandler setter method so that when there is an exception in any of the thread&#39;s &lt;i style=&quot;font-weight: bold;&quot;&gt;(all of the threads in the applicaiton)&lt;/i&gt;, this handler gets invoked.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The handler also catches the exceptions that are thrown in the main method too... &lt;b&gt;&lt;i&gt;figuring out how... obviously its too a thread (A Thread with a name as &quot;main&quot;).&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://saravanandorai.blogspot.com/feeds/2004838118941335572/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://saravanandorai.blogspot.com/2022/05/handling-exceptions-in-threads-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/2004838118941335572'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4074627129522097342/posts/default/2004838118941335572'/><link rel='alternate' type='text/html' href='http://saravanandorai.blogspot.com/2022/05/handling-exceptions-in-threads-in-java.html' title='Handling Exceptions in Threads in Java'/><author><name>Saravanan&#39;s Blog</name><uri>http://www.blogger.com/profile/04039541919608650126</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>