@BobHanlon is on the right track with the ErlangDistribution.
First we figure out how to generate a value for $x_1$ given that the sum of the $n$ independent exponential distributed random variables is 40. We have independent random variables $x_1\sim Exponential(\lambda)$ and $\sum_{i=2}^n x_i \sim Erlang(n-1,\lambda)$ and we want to find the conditional distribution of $x_1$ given that $x_1+\sum_{i=2}^n x_i =40$.
The joint distribution is found by
dist = TransformedDistribution[{x1, x1 + x2n}, {x1 \[Distributed] EponentialDistribution[\[Lambda]],
x2n \[Distributed] ErlangDistribution[n - 1, \[Lambda]]}];
The pdf and then cdf of $x_1$ given that the sum is 40 are
pdfx1 = FullSimplify[PDF[dist, {x1, sum}]/Integrate[PDF[dist, {x1, sum}], {x1, 0, sum},
Assumptions -> sum > 0], Assumptions -> n > 1 && x1 > 0 && sum > x1]
(* 40^(1 - n) (-1 + n) (40 - x1)^(-2 + n) *)
cdfx1 = Integrate[pdfx1, {x1, 0, x}, Assumptions -> n > 1 && x > 0 && sum > x]
(* 1 - 40^(1 - n) (40 - x)^(-1 + n) *)
Note that the pdf and cdf do not depend on $\lambda$. We can set the cdf to a Uniform[0,1] random variable and solve for x:
x /. FullSimplify[Solve[cdfx1 == u, x], Assumptions -> 0 <= u <= 1][[1]]
(* 40 - (-40^(-1 + n) (-1 + u))^(1/(-1 + n)) *)
We repeat that process for the remaining values (decrementing the total of 40 as we go).
n = 2000000;
sum = 40;
u = RandomVariate[UniformDistribution[{0, 1}], n - 1];
x = ConstantArray[0, n];
remaining = sum;
Do[x[[i]] = remaining - remaining (1 - u[[i]])^(1/(n - i));
remaining = remaining - x[[i]],
{i, 1, n - 1}];
x[[n]] = sum - Total[x[[1 ;; n - 1]]];
It takes about 7 seconds to generate the 2,000,000 values that sum to 40.
WorkingPrecision -> 50or similar insideRandomVariate. – MarcoB Oct 09 '21 at 18:22