Multiple connections with bank - Executable c # with multi task

0

I have an executable that I need to run a giant database. As the processing time would be unfeasible if I did in a single Thread .... Following the idea of this question , I decided to create an executable that does N tasks in parallel ... So basically I always do the same thing for different time intervals.

static void Main(string[] args)
{
        var dataInicio = DateTime.Now.AddDays(-35);
        var dataFim = DateTime.Now;

        var listaTasks = new List<Task>();

        while (dataInicio > dataFim ? dataInicio >= dataFim : dataInicio <= dataFim)
        {
            var d = dataInicio.Date;
            var meuBll = new MeuBll();
            listaTask.Add(Task.Run(() =>
                                        {
                                           meuBll.Foo(d);
                                        }).ContinueWith(
                                            x => meuBll.Dispose())
                               .ContinueWith(x => GC.Collect()));

            var meuBllNovo = new MeuBll();
            listaTask.Add(Task.Run(() =>
                                        {
                                            meuBllNovo.Boo(d);
                                        }).ContinueWith(
                                            x =>
                                            meuBllNovo.Dispose())
                               .ContinueWith(x => GC.Collect()));

            if (listaTask.Count >= 2 * 5)
            {
                Task.WaitAll(listaTask.ToArray());
                listaTask.Clear();
            }
            dataInicio = dataInicio > dataFim ? dataInicio.AddDays(-1) : dataInicio.AddDays(1);
        }
        Task.WaitAll(listaTask.ToArray());
So basically I chose to run, for example, a 10 day interval at a time, as you can see in if (listaTask.Count >= 2 * 5) , the problem is that my Foo and Boo methods have multiple connections to a single oracle database ...

public class MeuBll : IDisposable 
{
    private readonly OracleDal _oracleDal = new OracleDal();

    public void Foo(DateTime data)
    {

        var t1 = Task.Run(() =>
                     {
                         _listaSucesso = _oracleDal.ObterListaSucesso();
                     });

        var t2 =
            Task.Run(() =>
                         {
                             listaFalhas = _oracleDal.ObterListaFalhas();
                         });

        t1.Wait();
        t2.Wait();

        foreach (var sucesso in _listaSucesso)
        {
            //uma logica para inserir objetos em uma "lista de merge"
        }

        if (listaDeMerge.Any())
            Task.Run(() => _oracleDal.MergearLista(listaDeMerge)).Wait();
    }

    public void Dispose()
    {
        if (_hash != null)
            _hash.Clear();
        _hash = null;

    }
}

And my merge method:

    public void MergearLista(List<MyObject> listaMerge)
    {
        using (var conn = new OracleConnection(Connection.ConnectionString))
        {
            if (conn.State != ConnectionState.Open)
                conn.Open();
            using (var oCommand = conn.CreateCommand())
            {
                oCommand.CommandType = CommandType.Text;
                oCommand.CommandText = string.Format(@"
                MERGE INTO MyTable dgn 
                USING (select id from another_table where field = :xpe) d ON ( TO_CHAR(dateHappen, 'DDMMYYYY') = {0} and id = :xId) WHEN MATCHED THEN 
                    UPDATE SET OK = :xOk, dateHappen = SYSDATE
                WHEN NOT MATCHED THEN 
                    INSERT (fields....) 
                    VALUES (values...)");
                oCommand.BindByName = true;
                oCommand.ArrayBindCount = listaMerge.Count;



                oCommand.Parameters.Add(":xId", OracleDbType.Int32,
                                        listaMerge.Select(c => Convert.ToInt32(c.Id)).ToArray(), ParameterDirection.Input);

                oCommand.Parameters.Add(":xPe", OracleDbType.Varchar2,
                                        listaMerge.Select(c => Convert.ToString(c.Xpe)).ToArray(), ParameterDirection.Input);


                oCommand.ExecuteNonQuery();
            }
        }
    }
The problem is that for each day of processing, the process takes around 2 hours ... and daily has a routine to back up the bank, which makes it stand out for about 10 minutes, which will do my executable throw some Exception or simply lockar some table ..

What do I do? I stop the executable "in the hand" and put it to run again taking the days that it already executed ... In addition, many connections are simply opened ... So I kill these sessions in the hand too ...

How to solve this? Is there any way to force all open connections to simply close? Force% of% of them?

    
asked by anonymous 25.04.2016 / 17:17

0 answers